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.

1
  • Basically add success: function(data) { /* Do something with your response data */ } after async: false, Commented Sep 25, 2019 at 9:36

1 Answer 1

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); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.