i have the following jquery code running on my page just fine in FF and IE, but chrome seems to be freaking out..
in FF and IE the call is made and the result is app
after a day and a half i got over it, so may i present.....
function getBranchDetails(contactID, branchID) {
$.ajax({
type: "GET",
url: urlToRequestTo,
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: branchDetailsSuccess,
error: branchAjaxFailed
});
}
function branchDetailsSuccess(result) {
$("#divBranchControl").empty();
$("#divBranchControl").append(" " + result);
$("#branchDiv").tabs();
}
function branchAjaxFailed(result) {
if (result.status == 200 && result.statusText == "OK") {
//this is here only because chrome breaks on this method only for no reason whatsoever.
//chrome sees the request as failed, but everything happens fine...
branchDetailsSuccess(result.responseText);
}
else {
alert("FAILED : " + result.status + ' ' + result.statusText);
}
}
I don't know if you still have this issue, but I ran into a similar error just today. I was calling an aspx page to return a string with responseText and Chrome never returned anything. Turned out I had a Response.Close in my aspx page which worked everywhere else but probably didn't send some required headers or something to Chrome and/or Safari. Hope that helps someone.
In the AJAX operation just add: async: false
after datatype: "json"
, and that should solve your problem. Chrome has issue handling asynchronous calls.
Try this for success :
success: function(response) { branchDetailsSuccess(response); },
I just ran into this in Chrome (was fine in Firefox) and adding async: true
to the ajax parameters solved it.
I just saw that this question has gotten a lot of views, and its still open. I'd forgotten about it completely and hopefully this will let me close it.
Setting the datatype argument to nothing, or even removing the datatype argument completely will solve the problem.
In my example I am returning a rendered view (an html snippet in string) and in this code I'm specifying the data type to json, when really it isn't. Most other browsers seem to ignore the datatype if its incorrect and move on with life, allowing me to append the html result.
Chrome throws an error. The status text is OK, the status code is 200, because the actual ajax request went through fine. The problem has nothing to do with the request itself, the problem is that the data returned is not what I told chrome it would be.
So chrome breaks. If I remove the datatype argument completely chrome figures out what the data is when it gets it. If I set the datatype argument to "html" then it also works fine.
Long story short, the problem is not chrome. Its me. Because I'm dumb like that. I am marking this as the answer to this question as it answers the example I presented in the original question.
In the comments others have described other situations where this solution is most likely not going to help.