0

My current code is :

var dataReceiveString = $.ajax({
                    url: "getDataReceiveString.php?"+param,
                    dataType: "text",
                    async: false
                    }).responseText;

// code that make use of dataReceiveString ;

The obvious choice of changing false to true does not work.

How should the code be rearranged ?

Also to add a waiting circle gif animation while javascript do ajax call to php.

edit : question is different from Execute function after Ajax call is complete as avoiding use of async:false.

edit : question is different from How do I return the response from an asynchronous call? as it's too generic and not targetted to my question.

Winston L
  • 53
  • 6

1 Answers1

0

If you want to make it sync you can always rely to async functions:

    async function doAjax(args) {
        let result;

        try {
            result = await $.ajax({
                url: ajaxurl,
                type: 'POST',
                data: args
            });
            // code that make use of dataReceiveString
            return result;
        } catch (error) {
            console.error(error);
        }
    }
Mosè Raguzzini
  • 15,399
  • 1
  • 31
  • 43