1

okay so,

[browser] ==> makes AJAX call to webserver running php

i have the following php code,

<?php

  //Process Ajax request
  //return success code to browser

  //continue with other php code
 ?>

How exactly can i achieve the second part i.e "return success code to browser"? and continue with processing php code.

wolfgang
  • 7,281
  • 12
  • 44
  • 72
  • you could use output buffers and the `flush();` function to push some output to the browser before your script has completed. further reading here: http://www.php.net/manual/en/book.outcontrol.php – totallyNotLizards Mar 26 '14 at 10:20

2 Answers2

0
     put **async:false** in ajax call so your code will execute synchronously  means  until you don't get success or failure from ajax return rest of code will not execute .. do like following

   // add here jquery file 
   <script>
     $.ajax({
            url : "abc.com/page",
            type: "POST",
            data: {},
            async:false
            success : function(data)
            {
               //you can use data here
            }
    });
   </script>
   //you can write here php code
Niyati
  • 146
  • 10
-1

i think it can be done like follow

 //initial php code
 call_function();

 echo json_encode(array('success'=>true));

 //other php code
 call_function(); //etc

or you can split the ajax call in 2 parts.. in 1st part it will get the status so echo json_encode() will be executed and call ends and in success call back of ajax make 2nd call which will execute the remaining code!

Sagar Rabadiya
  • 4,126
  • 1
  • 21
  • 27