这是我向堆栈提出的第一个问题。
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/