Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

jquery ajax problem in chrome

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 appended to the div. in chrome, it calls ajaxfailed on failure.

the XMLHttpRequest passed to the AjaxFailed function has a status code of "200" and the statusText is "ok". the readystate is 4 and the responseText is set to the data i wish to append to the div.. basically from what i can see its calling the failure method but it isn't failing.. i have tried with both get and post requests and it always breaks in chrome.

function getBranchDetails(contactID, branchID) {
  $.ajax({
    type: "GET",
    url: urlToRequestTo,
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: branchDetailsSuccess,
    error: AjaxFailed
  });
}



 function branchDetailsSuccess(result) {
      $("#divBranchControl").empty();
      $("#divBranchControl").append(" " + result);
      $("#branchDiv").tabs();
    }



 function AjaxFailed(result) {
      alert("FAILED : " + result.status + ' ' + result.statusText);
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In the AJAX operation just add: async: false after datatype: "json", and that should solve your problem. Chrome has issue handling asynchronous calls.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...