How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?

Technology CommunityCategory: jQueryHow can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?
VietMX Staff asked 3 years ago

You specify the asynchronous option to be false to get a synchronous Ajax request. Then your callback can set some data before your mother function proceeds.

Consider:

beforecreate: function (node, targetNode, type, to) {
    jQuery.ajax({
        url: 'http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value),
        success: function (result) {
            if (result.isOk == false) alert(result.message);
        },
        async: false
    });
}