我在这里问,jQuery ajax() 中是否有任何设置参数,可以让我们在数据成功传输到 php 文件时调用函数,而不是在数据传输且 php 文件解析代码并返回值时调用函数.
我有以下代码:
$.ajax({
..
..
..
success: function(data) {
// do something
}
});
但我想要这样:
$.ajax({
..
..
..
onTransfer: function() {
// do something like show a div saying "Done".
},
success: function(data) {
// do something
}
});
最佳答案
你只从服务器端得到1个答案,成功有什么问题?如果您的流程花费的时间太长,那么您可以在脚本启动后立即返回,并显示“正在处理您的请求”作为成功
的结果:
<?php
ob_end_clean(); // discard everything
header("Connection: close"); // send Connection close
ignore_user_abort(true); // ignore user abort
set_time_limit(0); // no time limit
ini_set("memory_limit","200M"); // setup a memory usage needed
ob_start(); // start output buffer
header("Content-Length: 0"); // send lenght 0
ob_end_flush(); // end and flush
flush();
// continue your script
当您收到成功答案时,您的脚本将继续运行。
关于php - 当数据传输到php文件时调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17877549/