Simplify ajax query results testing
$.get("api/loadAll")
.done(function(){ alert("$.get succeeded"); })
.fail(function(){ alert("$.get failed!"); });Availible in jQuery >1.5. You can use any function in place of $.get. For my datacontext, I use something like this:
// Ajax helper
function ajaxRequest(type, url, data) { 
    var options = {
        dataType: "json",
        contentType: "application/json",
        cache: false,
        type: type,
        data: ko.toJSON(data)
    };
    return $.ajax(url, options);
}
// making a call
ajaxRequest("post", url, postData)
        .done(function (result) {
            // show user some love
        })
        .fail(function () {
            // and dont get mad
        });Written by Олег Гаврилов
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Js 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
 
 
