How to detect JQuery $.get failure? Seeking simple code example

前端 未结 3 783
旧巷少年郎
旧巷少年郎 2020-12-25 11:04

I\'m a JQuery n00b. I\'m trying to code a very simple using $.get(). The official documentation says

If a request with jQuery.get() returns an error code, it wi         


        
3条回答
  •  伪装坚强ぢ
    2020-12-25 11:38

    .get() is just a synonym for .ajax() with a number of options pre-set. Use ajax() to get the full range of options, including the error callback.

    $.ajax({
    type: "GET",
    url: "test.htm",
    error: function(xhr, statusText) { alert("Error: "+statusText); },
    success: function(msg){ alert( "Success: " + msg ); }
    }
    );
    

提交回复
热议问题