jQuery.ajax 类型 : Post to an ashx file not being initiated in IE. 在 FF、Chrome 和 Safari 中工作正常

标签 jquery ajax post ashx

这是我向堆栈提出的第一个问题。

jQuery.ajax 类型:发布到未在 IE 中启动的 ashx 文件。在 FF、Chrome 和 Safari 中运行良好

代码如下:

$.ajax({
    type: "Post",
        url: "http://[ ... ]loguserdata.ashx?" + dataString,
        data: "",
        cache: "false",
        contentType: "text/plain",
        success: function(msg){
            //alert( "Data Saved: " + msg );
        }
});

by 在 FF 等中工作正常。我的意思是调用 ashx 文件并记录信息。 我可以在 fiddler、firebug 和 chrome 等价物中看到 ajax 调用。

但在 IE9 或 IE 兼容模式下似乎没有发生恶作剧。

我可以获得上述代码的多个版本,以便在其他浏览器中工作。包括 $('#result').load( ...

但在 IE 中没有任何作用

顺便说一句,在 IE 本地运行良好。

哦,我不会对任何返回值给予任何关心。

这不是缓存问题。我在 querystring 的末尾添加了一个 date=getTime()

querystring (dataString) 看起来像 fname=john&lname=doedy

编辑:我已经解决了这个问题。明天有时间我会发布完整的答案。

最佳答案

长篇故事被删节: 您不能执行 XMLHttpRequest 跨域。使用 jQuery 的 getJSON 方法和查询字符串参数 &callback=?添加到网址。我相信这会将数据类型转换为 JSONP。

 var url = 'http://handlers.flowauto.com/eprice/loguserdata.ashx?fname=jim&callback=?';
        $.getJSON(url, function(data) {
            // do some stuff
        });

这里有一些链接帮助我解决了这个问题。

XMLHttpRequest cannot load an URL with jQuery

http://api.jquery.com/jQuery.getJSON/请参阅下面的摘录

JSONP If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

http://api.jquery.com/jQuery.ajax/请参阅下面的摘录

Additional Notes: Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol. Script and JSONP requests are not subject to the same origin policy restrictions.

关于jQuery.ajax 类型 : Post to an ashx file not being initiated in IE. 在 FF、Chrome 和 Safari 中工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7749272/

相关文章:

jquery - 如果选中输入,则将 class active 添加到字段集,其类等于输入的 id

javascript - Ajax 正在缓存表单 onclick 的先前输出

javascript - 在 Express.js 应用程序中,如何获取源 POST 数据(原始字符串)?

javascript - 通过 POST 下载文件

javascript - 通过 javascript 函数调用时,Fancybox iframe 不工作

php - 暂停恢复客户端-服务器文件上传

javascript - 如何用JS检查一个表中的所有复选框并为每个复选框做一个工作

jQuery:在 Ajax 内容上应用 CSS

http - 如何使用 curl 发布 XML 数据

jQuery 不返回 JSON,尽管通过浏览器返回它