开发者

When is jQuery.ajax() complete{}?

开发者 https://www.devze.com 2023-03-04 06:15 出处:网络
jQuery.ajax() is \"a function to be called when the request finishes\". Suppose I\'m making an ajax request to ajax.php:

jQuery.ajax() is "a function to be called when the request finishes". Suppose I'm making an ajax request to ajax.php:

<?php

echo 'complete';

some_functions_that_echo_nothing();

?>

Will the complete have to wait for some_functions_that_echo_nothing()? If so, is there a way to make the complet开发者_StackOverflow社区e{} occur right after the echo and still have the ajax.php run through till the end?


Try calling HttpResponse::send();


I'm guessing you want to output "Complete" and let that function run in background, since it's very slow.

In that case put this function in a separate file. Let it be proc.php and use this instead:

<?php
    echo "Complete';
    exec ("/usr/bin/php proc.php >/dev/null &");
?>

That will return right away and fire the proc.php file to run on background. Of course it won't be able to output it's return to the user, so it should mail the user when he's done, or do his own persistence.

EDIT: ALWAYS take grea care of what you put inside exec statements. Never put user inputs into it if you are not 100% sure you are sanitizing it very carefully. Even so, you really don't have a good reason to use User input into an exec call.

0

精彩评论

暂无评论...
验证码 换一张
取 消