how can i get jquery to perform a synchronous rather than asynchronous ajax re


I have a JavaScript widget which provides standard extension points. One of them is the beforecreate function. It should return false to prevent an item from being created.

I've added an Ajax call into this function using jQuery:

beforecreate: function (node, targetNode, type, to) {
  jQuery.get('' + + '?name=' + encode(to.inp[0].value),

  function (result) {
    if (result.isOk == false) 

But I want to prevent my widget from creating the item, so I should return false in the mother-function, not in the callback. Is there a way to perform a synchronized Ajax request using jQuery or any other API?


With async: false you get yourself a blocked browser. For a non blocking synchronous solution you can use the following:


With ES6 you can use a generator & the co library:

beforecreate: function (node, targetNode, type, to) {
        let result = yield jQuery.get('' + + '?name=' + encode(to.inp[0].value));
        //Just use the result here


With ES7 you can just use asyc await:

beforecreate: function (node, targetNode, type, to) {
    (async function(){
        let result = await jQuery.get('' + + '?name=' + encode(to.inp[0].value));
        //Just use the result here
By : Spen

You can put the jQuery's Ajax setup in synchronous mode by calling


and then perform your Ajax calls using jQuery.get( ... );

then just turning it on again once


I guess it works out the same thing as suggested by @Adam, but it might be helpful to someone that does want to reconfigure their jQuery.get() or to the more elaborate jQuery.ajax() syntax.

By : Sydwell

Keep in mind that if you're doing a cross-domain Ajax call (by using JSONP) - you can't do it asynchronously, the "async" flag will be ignored by jQuery.

    url: "testserver.php",
    dataType: 'jsonp', // jsonp
    async: false //IGNORED!!

For JSONP-calls you could use:

  1. Ajax-call to your own domain - and do the cross-domain call server-side
  2. Change your code to work asynchronously
  3. Use a "function sequencer" library like Frame.js (this answer)
  4. Block the UI instead of blocking the execution (this answer) (my favourite way)

This video can help you solving your question :)
By: admin