ajax - get statusCode inside jQuery load event handler -


Markup code:

I am using jQuery's AJAX event 'Load' H1> & lt; Iframe id = "my_iframe" src = "http: // somewhere" & gt; & Lt; / Iframe & gt;

jQuery code:
  $ (function () {$ ('# my_frame'). Load (function (data) {// content load Maybe 404/500 here or else. If (statusCode == 400) {// do something.} Else {// do something else}}}}}});   

question

I have to obtain the status code in my weight event callback. Maybe get the jqxhr object?

Is this possible?


And, I can manually change the src attribute of the iframe, which will also trigger the load event, it seems that this is not an AJAX call.

First of all, it is usually iframes . & lt; Div & gt; By using the element you should be able to meet all your requirements.

HTML:

  & lt; Div id = "dynamic page" & gt; Loading ... & lt; / Div & gt;   

Javascript:

  $ ("#dynamic page") Load ("http: // somewhere", function (response, position, xhr) {if (condition == "success") {// successfully request //} and (status == "error" || condition == " Timeout ") {// error and TIMEOUT request / / var msg =" Sorry! An error has occurred, please try again later "; $ (" #dynamic page ") .html (msg);} and if (Status == "No Modified") {// No Modified Request (Expected Cached) // If else (Status == "Abortion") {// ABORTED Request}}}}   

Some other suggestions on this question Carefully Walking With Another Post also did not use " success" as jQuery.load () and misspelling " success: " "

As a bonus treatment (if you are possibly misleading), you can easily customize the above code to use the loading animation. / Em>

Reference:

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -