开发者

Dojo xhrGet only returning null

The following Dojo code's load callback returns null. There shouldn't be any problem because jQuery's ajax works fine. What am I missing here?

Dojo version - doesn't work

dojo.xhrGet({
    url:"http://localhost:11039/",
    handleAs:"json",
    load: function(data){
        console.log(data); // Prints null
    },
    error: function(err){
        console.log('Error: ' + err);
    }
});

jQuery version - works

$.ajax({
    url:"http://localhost:11039/",
    type: 'GET',
    dataType: 'json',
    success: function(res){
        console.log(res) // Prints some JSON
    },
    error: function(err){
        console.log('ERROR: ' + err);
    }
});

Looking at Firebu开发者_如何学编程gs net tab I notice that the jQuery version is in fact sending a GET request:

GET localhost:11039    200OK     localhost:11039     62.8KB

while the Dojo version... "OPTIONS"?

OPTIONS localhost:11039    200OK     localhost:11039     62.8KB

Additional Details:

  • I get the same result in Ffox, Chrome and Safari.


Dojo sending an OPTIONS request usually means dojo considers it a cross-domain request.

The OPTIONS request is checking for the Access-Control-Allow-Origin header to see if the request should be performed, even though it is considered cross-domain.

See https://developer.mozilla.org/En/HTTP_Access_Control for more details

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜