-2

I'm trying to get echoed variable from php and display on the console. I'm using jquery to send data and I know the backend php file script is working fine. Since I want to see the progress and the backend php script echo out the iteration number while the script is running, I'm trying to see how I can get the echoed variable with jquery and display on the console.

I've tried success, onloading but it doesn't seem to work. Any help would be very appreciated. Thank you!

EDIT

$.ajax({
    url: location,
    type: 'POST',
            data:{
            iteration:"10",
            readsize:"200",
            slimdepth:"3",
            sourcedirectory:source,
            packagepath:MP
            },

    dataType:'json',
    success: function (response) {
        console.log("SUCCESS!");
                    console.log(response);
    },
    onInteractive:function (response) {
        console.log(response.responseText);
     },      
    complete:function (response) {
        console.log(response.responseText);
    },
    error: function (response) {
        console.log("Failure!");
        console.log(response.responseText);
    }

}); 

So this is how I send the data and backend php script gets the parameters without problems and it runs. Now I can't see anything until php is done running and then it echo everything. In the backend php script, I have iteration number that I want to check and that is the problem since I can't check while it is running but only it is done running.

Jules
  • 105
  • 9
  • 2
    relevant? http://stackoverflow.com/questions/22502943/jquery-ajax-progress-via-xhr – Marc B Nov 13 '14 at 18:25
  • 2
    Maybe you show us some code? – u_mulder Nov 13 '14 at 18:26
  • I don't think it is much relevant because I want to capture the echoed variable from php script while it is running. The link, as I understand, explains how to check the progress itself not actual data from php file. Let me know if I understood wrong. – Jules Nov 13 '14 at 18:34
  • What kind of progress do u want to check? I would recommend that U break this process up in 2. One is your worker progress. This progress does it stuff and reports his action in lets say a textfile or a database. The second process will do the polling to the response of the first. Reading out the textfile or the database – DarkBee Nov 13 '14 at 18:53
  • In the back end php file, there is for loop to increase iteration number once chuck of code inside for loop is done. It is quite long. I echo the iteration number, but jquery inside my code does not print out while it is running but only after it is all done. – Jules Nov 13 '14 at 19:04
  • Once the iteration is done, the file that is created is input to another script and later it creates a final report. So what I want to check if the iteration number while the script is running. I want to check the progress – Jules Nov 13 '14 at 19:04
  • Well U should report the iteration progress to a non-locking source and poll that source :) – DarkBee Nov 13 '14 at 19:09

1 Answers1

0

From what I could understand from your question probably this is what you are looking for. You are sending data to PHP file with jQuery post or send:

$.post(file.php, {post}, function(data){

});

If you want to log returned data from php in console you must use console.log() function:

$.post(file, {post}, function(data){
  console.log(data)
});

and now data will be logged into browser console.

blelump
  • 3,233
  • 1
  • 16
  • 20
alphawow
  • 390
  • 2
  • 7