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

发布于 2024-12-09 07:50:35 字数 868 浏览 2 评论 0原文

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

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

。类似的东西fname=john&lname=doedy

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

this is my first question to the stack.

jQuery.ajax type: Post to an ashx file not being initiated in IE. works fine in FF, Chrome, and Safari

Code below:

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

by works fine in FF, etc. I mean the ashx file is called and info is logged.
I can see the ajax call in fiddler, firebug and chrome's equivalent.

but there doesn't seem to be jackchit happening in IE9 or in IE compatibility mode.

I can get several versions of the code above to work in the other browsers. Including a $('#result').load( ...

but NOTHING works in IE

btw, works fine locally in IE.

oh, and I don't give a diddly poo about any return value.

and it's not a cache issue. I have a date=getTime() tacked onto the end of the querystring.

querystring (dataString) looks something like fname=john&lname=doedy

EDIT: I have solved this issue. I will post a thorough answer tomorrow when I have time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

话少心凉 2024-12-16 07:50:35

长篇故事被删减:
您不能执行 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 无法使用 jQuery 加载 URL

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

JSONP 如果 URL 包含字符串“callback=?” (或类似的,如
由服务器端API定义),请求被视为JSONP
反而。请参阅 $.ajax() 中对 jsonp 数据类型的讨论
更多详细信息。

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

附加说明:由于浏览器安全限制,大多数“Ajax”
请求受同源政策约束;请求不能
成功检索来自不同域、子域或的数据
协议。脚本和JSONP请求不受同源约束
政策限制。

Long story truncated:
You can't do a XMLHttpRequest crossdomain. Use jQuery's getJSON method with the querystring parameter &callback=? added to the url. This I believe converts the datatype to JSONP.

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

Here are a few links that helped me solve this.

XMLHttpRequest cannot load an URL with jQuery

http://api.jquery.com/jQuery.getJSON/ see excerpt below

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/ see excerpt below

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.

快乐很简单 2024-12-16 07:50:35

由于您没有发送 POST 数据,请尝试以下操作:

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

Try this since you aren't sending POST data:

$.ajax({
    type: "GET",
        url: "http://[ ... ]loguserdata.ashx?" + dataString,        
        cache: "false",
        contentType: "text/plain",
        success: function(msg){
            //alert( "Data Saved: " + msg );
        }
});
江南烟雨〆相思醉 2024-12-16 07:50:35

检查您的 IE 安全性,因为它在本地工作。我猜想 locahost 上的文件有更多的权限。

编辑:

IE9阻止跨域ajax调用,Opera浏览器也是如此。
对于 IE9,您可以阅读这篇文章 ,寻求解决方法。建议使用 XDR (XDomainRequest) 而不是通常的 XMLHttpRequest。

Check your IE security, since it's work locally. I guess that files on the locahost have more privileges.

Edit:

IE9 prevent doing cross-domain ajax call, Opera browser too.
For IE9 you can read this article, for a workaround. It suggest to use XDR (XDomainRequest) instead of the usual XMLHttpRequest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文