0

我正在从 yxcom 向 x.com 发出 ajax 请求,除了 IE 8 和 9 之外,我在大多数浏览器中都可以正常工作,在这些浏览器中我收到拒绝访问错误。这是我的代码

 if (!empty && radio_checked) {
        $(".modal-content").animate({
            height: "250px"
        }), 500, function () { };
        $.support.cors = true;
        var url = "localhost:5603/ajax/post/sell-exm/?" //localhost for testing locally


        if ($.browser.msie && window.XDomainRequest) {

            var xdr = new XDomainRequest();
            xdr.open("post", url+data); // *** ERROR HERE ***
            xdr.send(data); 

        } else {
            $.ajax({
                type: "POST",
                url: url,
                data: data,
                datatype: "jsonp",
                success: function(r){
                    //nothing needed here
                }
            });
        }
 }

同样,这适用于除 IE 8 和 9 之外的所有浏览器。此外,我在 web.config 上有一个 Access-Control-Allow-Origin 自定义标头。

4

1 回答 1

0

I'm not exactly sure if this is how XDR works, but it works like this on my server for some reason, but it looked like 'open' triggered the ajax response from my .Net back-end, and blocked the send from getting through (It doesn't sound right, but that's is how it looked in Fiddler). So no form data was being posted, which caused all the weirdness to happen.

To fix this, I changed the post to a get, and added a clause to my .Net Ajax Controller that said if Request.Form.AllKeys.Length = 0, get the query string instead.

于 2013-06-28T20:45:12.277 回答