Good evening.

There is such a simple AJAX script:

function go_news ( id ) { var go_id = id; var search = 'id_go'; $.post('site.php', { go_id: go_id, search: search }, function(data){ $('#info').html(data); }); return false; }; 

And php file:

 if ($_POST['search'] == 'id_go') { //Замена $go_id = str_replace('', '', $_POST['go_id']) //И так далее //а тут уже конечный ответ к примеру echo $go_id; } 

How to make that when functions were performed in php, I had the answer in the form of text, what stage is being performed in

 <div id="info">Тут ответ и результат потом уже</div> 

?

I have a function for php, and I can't figure out how to use it with AJAX.

 function printJson($info, $error = false) { @header( 'Content-Type: text/html; charset=UTF-8' ); if (!$error) { echo $info; return null; } $json = array( 'text' => '<span>' . $info . '</span>' ); echo json_encode( $json ); exit( ); } 
  • Explain in more detail what you want? The question is especially unclear: "How to make it so that when functions were performed in php, I had the answer in the form of text, what stage is being performed in ...". - MarinaVoin

1 answer 1

As I understand it, this is like "5% accomplished. This is being copied."

The scheme is as follows:

  1. You send an AJAX request for a script that performs actions - let's call it do.php.
  2. In AJAX, you configure that until the request is completed, you execute the function. The function sends a request to another script once every 5 seconds - let's call it report.php. The essence of this script is to read the information about the execution of the do.php script from the source (file, database, cache), which also writes information there at runtime.