2016-07-28 7 views
1

mit würde ich gerne wissen, wie Fehler zu behandeln für $ .post oder $ .get

$.post(URL,data,function(data,status,xhr),dataType) 
$.get(URL,data,function(data,status,xhr),dataType) 

ohne .ajax $ mit welches einen Fehlerhandler hat.

$.ajax({ 
    url: url, 
    type: $(this).attr("method"), 
    dataType: "JSON", 
    data: data, 
    processData: false, 
    contentType: false, 
    success: function (data, status) 
    { 

    }, 
    error: function (xhr, desc, err) 
    { 


    } 
}); 
+0

http://api.jquery.com/decred.fail/ –

Antwort

1

jQuery post und get promisses sind, so dass Sie die Funktionen Kette done, fail und always auf diese:

var jqxhr = $.post("example.php", function() { 
    alert("success"); 
}) 
.done(function() { 
    alert("second success"); 
}) 
.fail(function() { 
    alert("error"); 
}) 
.always(function() { 
    alert("finished"); 
}); 

Oder sogar später von einem Varibale:

jqxhr.always(function() { 
    alert("second finished"); 
}); 

See the documentation.

Verwandte Themen