在onpaste事件中发出ajax请求时访问被拒绝 [英] Access denied when making ajax request in onpaste event

查看:499
本文介绍了在onpaste事件中发出ajax请求时访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net mvc网站我正在ajax调用我的服务器,当用户粘贴在某个文本框中的东西。这个调用过去在IE 8工作,但现在它停止工作在IE 11,给我一个访问拒绝异常在我的jQuery 1.7.1在 h.open(c.type,c.url,c .async)

In my asp.net mvc website I am making an ajax call to my server when the user pastes something in a certain textbox. This call used to work in IE 8, but now it stopped working in IE 11, giving me an access denied exception in my jQuery 1.7.1 at h.open(c.type,c.url,c.async).

长时间的研究暗示我可能与CORS问题相关,但...每个调用都在同一个域。

Long research hinted me that it might be related to a CORS issue, but... every call is on the same domain.

<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>

当尝试直接进行同一个通话时,让我们说通过一个简单的链接:

When trying to make the same call directly, let's say via a simple link:

<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>

它的工作原理正如预期的...(没有访问被拒绝)

It works just as expected... (no access denied)

有人知道如何让它运行吗?

Does anybody have an idea how to get this to run?

谢谢!

推荐答案

由于它只在粘贴时无效,所以问题似乎是粘贴事件处理程序。

Since it doesn't work only when pasting, the problem seems to be with the paste event-handler.

对于IE11的问题和我发现的粘贴事件

After searching for problems with IE11 and the paste-event I found among others "IE11 pasting clipboard data to an input element annoyance" on StackOverflow.

这可能是一个长镜头,但你可以尝试相同的解决方案 =解决方法),AlvinfromDiaspar在该文章中提供回答

It might be a long shot, but a you could try the same "solution" (=workaround) that AlvinfromDiaspar provided as answer in that post:

$('#Pasteexcelhere').on('paste', function () { setTimeout(blubb, 100) });

这篇关于在onpaste事件中发出ajax请求时访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆