开发者

jQuery ajax fails for unknown reason

I'm calling a function like this:

function(activeOnly, callback) {
    debug("$.support.cors: {0}".format($.support.cors));
    debug("getting data({0})".format(activeOnly));
    debug("{0}/data/".format(this._api_root));
    $.ajax({
        url: "{0}/data/".format(this._api_root),
        data: {
            generaldata: !activeOnly
        },
        dataType: "json",
        headers: {
            authorization: this._auth_header
        },
        success: function (data, code, jqx) {
            debug("data request succeeded with {0}".format(data));
            result = data;
        },
        error: function(jqx, err, ex) {
            debug("data request failed with {0}: {1}".format(err, ex));                 
        },
        complete: function(jqx, status) {
            debug("data request completed: {0}".format(status));                    
        }
    });
开发者_StackOverflow社区

In response, the error and complete functions are called, with the resulting output:

[6192] MyData: $.support.cors: true
[6192] MyData: getting data({0})
[6192] MyData: https://_some_root_/data/
[6192] MyData: data request failed with Unknown: Unknown
[6192] MyData: data request completed: Unknown

When I monitor using Charles, this is what I get:

https://_some_root_/
Failed
No request was made. Possibly the certificate was rejected.
-
HTTP/1.0
CONNECT
-
/127.0.0.1
_some_root_/_some_ip_address_

3/31/11 3:15:28 PM
-
-
-
-
-
-
-
0.02 KB/s
-

366 bytes
-
-
-
366 bytes
-
-

and in the request tab, I can see that my request doesn't even look right (note the lack of an Authorization header):

CONNECT _some_root_:443 HTTP/1.0
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; Tablet PC 2.0)
Host: _some_root_:443
Content-Length: 0
Proxy-Connection: Keep-Alive
Pragma: no-cache

What gives? There is no prompt for an unrecognized certificate or anything like that - it just fails. (It works fine if I make a GET request in my browser).


This appears to be a known bug

  1. According to the reporter the workaround/hack is to change the jQuery source from

    jQuery.support.cors = testXHR && ( "withCredentials" in testXHR );
    

    to

    jQuery.support.cors = true; 
    
  2. A comment on the bug has this to say:

    Thanks for the bug report, but this is not a jQuery bug. Windows 7 Gadgets is not a supported jQuery platform. The transports layer of new ajax is pluggable, so you should just include a custom transport that ignores normal cross-domain support (or uses XDomainRequest).

  3. ...and

    Or, more simply, set jQuery.support.cors to true in your script without hacking into jQuery ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜