Response time from Ajax

Asked

Viewed 587 times

1

Guys I’m doing my first AJAX and I’m having a problem which is this. It calls a PHP routine that downloads and uploads via FTP one or more files. And this may take a while. How do I keep AJAX waiting because it’s finishing before the answer.

Pastbin with the code

  • http://answall.com/questions/6392/awaitr-retorno-de-ajax-em-fun%C3%A7%C3%A3o-s%C3%Adncrona but I don’t recommend using it this way.

  • @Rafaelwithoeft has already put async=false and da in it it returns the value of the empty Date. If I try to run the url by POSTMAN which is a Chrome extension to run API Rest it returns me the correct JSON: {"status":true,"message":"Spreadsheet.pdf -> Successfully shipped. "}

  • After all what you want to wait for, the $ajax or the $post you’re using?

  • $post, forgot to comment. Sorry

  • $.post is asynchronous, you need to use $.ajax and set async to false, that way you will be Able to Wait for the Response. You can read more about it here: http://api.jquery.com/jQuery.ajax/ (http://stackoverflow.com/questions/10575214/how-to-wait-for-response-in-post-jquery)

  • @Rafaelwithoeft redid the code and the 2 consoles in the code continue to return blank. Now I am realizing that it is taking longer to return the answer. See the new code: http://pastebin.com/eiv2Pd5P

  • Are you sure you’re going to the right URL, that you’re returning something, or that you’re not making a mistake? Looked at your console (F12 - Chrome) to see if there are no errors?

  • I checked everything, including it triggers the URL she starts downloading the file and aborts. Then I test it via the POSTMAN and all right it makes the download and upload correctly and back to the concluding message without errors. Try there creates a PHP routine that takes about 30 seconds or more and see that it will not wait.

  • Exactly, because it aborts requests that pass 30 seconds. This is php configuration not javascript. In your PHP try to put something like: ini_set('max_execution_time', 300); /300 seconds = 5 minutes (http://stackoverflow.com/questions/5164930/fatal-error-maximum-execution-time-of-30-seconds-exceeded)

  • I think not because if I perform the routine without calling AJAX it takes and does everything right. only when I call via ajax she does not perform.

  • Try this then: http://stackoverflow.com/questions/14798196/ajax-request-max-execution-timing-out

  • I tried and clocked the time with 12 seconds it returned the empty answer. In Chrome it marked 12.81 seconds waiting on this call.

  • Can’t you put AJAX running a PHP file that doesn’t need an answer? or you can switch to websockets to stay open?

Show 8 more comments

1 answer

1

In this case you can use the parameter timeout to place a timeout greater than the standard I believe to be 30 seconds.

$.ajax({
  url: '/...',
  timeout: 600000,
  success: ...
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.