JQuery: using one Ajax call, get progressive statuses instead of one answer?

I'm just wondering ... is it possible to get multiple responses from a single ajax call? I think solely for aesthetic purposes, to update the status on the client side.

I have one ajax method calling submit form

$.ajax({
  url: 'ajax-process.php',
  data: data,
  dataType: 'json',
  type: 'post',
  success: function (j) {
  }
});

I can only get one response from the server side. Is it possible to get intermittent statuses? For instance:

Default (first): create an account Next: Email confirmation Next: Done

Thank you for your help!:)

+3
source share
3 answers

From a single ajax call, I don't think it is possible.

- , ( , gmail, ). ajax , ajax-, , . " ", , .

+2

- comet, "push" , , , , , .

, , , script "". , , , , .. . , . , ajax , , , - , .

, , PHP, , , , , , script.

- , , , ajax .

:

[http://plugins.jquery.com/project/ajax-http-stream]

. :

-, , xmlhttprequest.responseText ( imo). , , .

, , , , , , , ajax .

, script , "status.xml" "status.txt". ajax ajax, .

0

, backend script. , , . , , " ". , , php ( ) script . php - :

  while($response !== 'I'm done'){  
      sleep(1);
  }else{
      return $some_value;
      exit();
  }

script . sleep (1) script 1 , . . php script .

, , . , abort script. - , script. , javascript.

In the tests that I did. I made the initial ajax call, and when the value was returned, I made another ajax call so that your back end of the script will not time out. I only talked to this on my local server, so I'm not sure how this is the real world, but it works.

0
source

Source: https://habr.com/ru/post/1728884/


All Articles