$.ajax({ async:false, url: "ajax/stop_billed_reservation_delete.php", type: "POST", dataType : "json", data : { "rid" : <?php echo $_GET['reservationId']; ?> }, success: function(result){ console.log(result); return result; } });
my target is return ajax response. but before the return response script run other parts. How can i fix this issue !
ajax response should be true or false so return value should be true or false
This script is used for stop to form submission. if return value is true, form should submit, otherwise (false) for should be not submit.
( This code is used to validate form )
Advertisement
Answer
Ajax by default is asynchronous hence why it is not waiting for the ajax response. async: false
would not work because it is already deprecated. You can run the form submission in the success function of the ajax function.
$.ajax({ url: "ajax/stop_billed_reservation_delete.php", type: "POST", dataType : "json", data : { "rid" : <?php echo $_GET['reservationId']; ?> }, success: function(result){ console.log(result); if(result){ submitForm(); //Run the function that will submit the form. } } }); function submitForm(){ //Relevant code for submitting the form. . . . . . . }