简体   繁体   中英

jQuery Ajax .post() issue

I have the following code:

$(document).ready(function() {

     console.log("Document ready...");

     $.post("...file.asmx/HelloWorld", function(data) {

          console.log("Post Successful");               
     });            
});

I get the following console output:

[10:01:44.528] Document ready...
[10:01:44.601] POST ..file.asmx/HelloWorld [HTTP/1.1 200 OK 103ms]

My question is why is the second log call not executing? It seems like the post was successful and the function should execute. I'm using firefox.

Also:

$(document).ajaxError(function(event, jqxhr, settings, exception) {
      console.log( "Triggered ajaxError handler." );
      console.log(exception);
});

When I try and log the exception I get a blank line in my console.

A 200 OK response does not guarantee a successful AJAX call.

Cross-origin Resource Sharing rules might prohibit access to the resource, or the content returned might be unparsable.

Add an error callback and look to see if that's called, and if so, with what arguments.

Since $.post doesn't directly support an error callback, you can use "deferred" syntax:

$.post(...).fail(function(jqXHR, textStatus, errorThrown) {
    // log here
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM