try*_*kyn 1 javascript ajax jquery cors
在我的asp.net mvc网站上,当用户在某个文本框中粘贴某些内容时,我正在对我的服务器进行ajax调用.此调用曾在IE 8中工作,但现在它在IE 11中停止工作,在我的jQuery 1.7.1中给了我一个访问被拒绝的异常h.open(c.type,c.url,c.async).
长期研究暗示我可能与CORS问题有关,但......每次通话都在同一个域上.
<input type="text" id="Pasteexcelhere" name="Pasteexcelhere" />
<script type='text/javascript' >
$(function () {
onp();
});
function onp() {
obj = document.getElementById('Pasteexcelhere');
$('#Pasteexcelhere').on('paste', function (e) {
x = obj.value;
$.ajax({
type: "POST",
url: "<%= Url.Action("PasteFromExcel", "RequestData" ) %>",
data: "{'data': '" + x + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
traditional: true,
success: function (da) {
alert("success");
},
error: function (d) {
alert(d.statusText); // access denied
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
当试图直接拨打同一个电话时,我们可以通过一个简单的链接说:
<a id="mylink" href="#" onclick="blubb();return false;">Pasted</a>
<script type='text/javascript' >
function blubb() {
obj = document.getElementById('Pasteexcelhere');
x = obj.value;
$.ajax({
type: "POST",
url: "<%= Url.Action("PasteFromExcel", "RequestData" ) %>",
data: "{'data': '" + x + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
traditional: true,
success: function (da) {
var propertyGrid = $('#RequestedTickers').data('tGrid');
propertyGrid.rebind({});
},
error: function (d) {
alert(d.statusText);
}
});
};
</script>
Run Code Online (Sandbox Code Playgroud)
它按预期工作...(没有拒绝访问)
有没有人知道如何让它运行?
谢谢!
由于它仅在粘贴时不起作用,因此问题似乎与粘贴事件处理程序有关.
在使用IE11和粘贴事件搜索问题后,我发现StackOverflow上的" IE11将剪贴板数据粘贴到输入元素烦恼 ".
这可能是一个长镜头,但你可以尝试AlvinfromDiaspar 在该帖子中提供的相同"解决方案"(=解决方法)作为答案:
$('#Pasteexcelhere').on('paste', function () { setTimeout(blubb, 100) });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1364 次 |
| 最近记录: |