jQuery 1.6 cross domain request is not working
I'm testing a vanilla html website that requests data from a web service. My website is running locally on port 81 and the web service is running on port 61616.
This worked in jQuery 1.4.
I have since upgraded to 1.6 and seriously thinking of going back because the cross domain implementation is broken.
In IE I get resource not found and the URL shown is everything except the hostname:port, without which, the resource (of course) will not be found.
In Chrome I get the following error: XMLHttpRequest cannot load http://localhost:61616/ZifmiaService/Register/foo/bar/foo bar/david@company.com. Origin http://localhost:81 is not allowed by Access-Control-Allow-Origin.
The web service has Access-Control-Allow-Origin:* set, so cross domain requests are allowed on the server side.
I also have:
$.support.cors = true;
in my client side javascript code.
I am not using jsonp an开发者_JAVA百科d don't think I should need to with the correct settings.
What else could I be doing wrong, or should I report a bug to jQuery?
- Added code * *
The url becomes the 61616 url as described above.
this.register = function (username, password, nickName, emailAddress, callback, errorCallback) {
$.ajax({
type: "GET",
url: ZifmiaRegister.format(username, password, nickName, emailAddress),
crossDomain: true,
dataType: "json",
success: function (zifmiaRegistrationViewModel) {
callback(zifmiaRegistrationViewModel);
},
error: function (xhr, textStatus, errorThrown) {
errorCallback(xhr, textStatus, errorThrown);
},
beforeSend: function () { $(ajaxLoading).show(); },
complete: function () { $(ajaxLoading).hide(); }
});
}
Try to append "?callback=?" to the URL where the ajax request is made. For example, "http://localhost:61616/ZifmiaService/Register/foo/bar/foo bar/david@company.com?callback=?" .
If your URL contains query strings, you should add "&callback=?".
精彩评论