8
I have a question. I need to cancel an AJAX request on the client side and the server side.
On the client side I use the abort()
var requisicao = $.ajax({ url : 'xyz.php' });
if(requisicao && cliente_abortou_requisicao){
requisicao.abort();
}
Now on the server side I’m doubtful. How do I stop PHP from running? Because if I only do it on the client side, script still runs on the server and if I make another AJAX request to the server this request is waiting for the end of the previous request.
Example:
<?php
$DB = getConexaoOracle();
$sql = "SELECT * FROM FUNCIONARIOS"; // 1 milhão de registros (exemplo)
$RS = $DB->Execute($sql);
$array_de_retorno = array();
while($RS->hasNext()){
...
}
die(json_encode($array_de_retorno));
?>
Would anyone know how to treat that this session was aborted by the client?
Ajax requests last between 0.1 and 1 second in 99.9999% of cases. What is the scenario that needs this feature? I am not saying that it is not valid, but it would be interesting to know the problem to help better in the solution.
– Sergio
I am using an asynchronous AJAX request to carry out the printing of an order report. which, depending on the Representative, can take up to 5 minutes. But sometimes they don’t want to wait.
– Don't Panic
This may help, take a look. http://stackoverflow.com/questions/16810339/how-to-cancel-a-php-process-when-ajax-call-is-cancelled
– Augusto
Test add "async: false" to your ajax call.
– Paulo Martins
This does not seem to be the right way to try to solve it. Perhaps this other question gives you some light: http://answall.com/questions/164938
– Daniel Omine
Daniel, caching the result would not be good for me because I use price rules. A X product may have a different price per N variable ( status, tax classification, category, payment condition, etc.), for example, a 1 product query takes on average 1 second, If the user wants to search the products of a Product Line that can have up to 3,000 products if it does not specify a better filter, the system will process and get stuck in the request for 3,000 seconds. I wish I could give him the option to cancel the request and redo the filter more quickly.
– Don't Panic