David Cornelson
David Cornelson

Reputation: 11

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/[email protected]. 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 and 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?

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

Upvotes: 1

Views: 1899

Answers (1)

Stefan Filip
Stefan Filip

Reputation: 1801

Try to append "?callback=?" to the URL where the ajax request is made. For example, "http://localhost:61616/ZifmiaService/Register/foo/bar/foo bar/[email protected]?callback=?" .

If your URL contains query strings, you should add "&callback=?".

Upvotes: 1

Related Questions