JQuery-AJAX:表单发布超时和延迟后不再请求
我得到了一个包含多个复选框的表单。该表单应发送到服务器以从服务器端脚本接收适当的结果。
这已经在起作用了。
我现在要实现的目标:
1)实现超时:这已经可以工作,但是一旦发生超时,新的请求就不再工作。
2) 在请求结果中实现延迟:应实现延迟,以便并非每个复选框都会产生 POST 请求。
这就是我现在所拥有的:
function update_listing() {
// remove postings from table
$('.tbl tbody').children('tr').remove();
// get the results through AJAX
$.ajax({
type: "POST",
url: "http://localhost/hr/index.php/listing/ajax_csv",
data: $("#listing_form").serialize(),
timeout: 5000,
success: function(data) {
$(".tbl tbody").append(data);
},
error: function(objAJAXRequest, strError) {
$(".tbl tbody").append("<tr><td>failed " + strError + "</td></tr>");
}
});
return true;
}
结果现在作为 HTML 表行传递 - 我将在下一步中将它们转换为 CSV/JSON。
非常感谢您的建议。
I got a form containing multiple checkboxes. This form shall be sent to the server to receive appropriate results from a server side script.
This is already working.
What I would achieve now:
1) Implementing a timeout: This is already working, but as soon as a timeout occurs, a new request is not working anymore.
2) Implementing a delay in requesting results: A delay shall be implemented so that not every checkbox is resulting in a POST request.
This is what I have right now:
function update_listing() {
// remove postings from table
$('.tbl tbody').children('tr').remove();
// get the results through AJAX
$.ajax({
type: "POST",
url: "http://localhost/hr/index.php/listing/ajax_csv",
data: $("#listing_form").serialize(),
timeout: 5000,
success: function(data) {
$(".tbl tbody").append(data);
},
error: function(objAJAXRequest, strError) {
$(".tbl tbody").append("<tr><td>failed " + strError + "</td></tr>");
}
});
return true;
}
Results are for now passed as HTML table rows - I will transform them to CSV/JSON in the next step.
Thanks so much for your advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于延迟:
这将等待一秒钟,直到发出 AJAX 请求。 “一旦发生超时,新的请求就不再有效”是什么意思。如果您想在失败时触发另一个请求,只需再次调用
update_list()
(但请注意,1 秒的延迟将生效)。For the delay:
This will wait a second until making the AJAX request. What do you mean with regards to "as soon as a timeout occurs, a new request is not working anymore.". If you want to trigger another request if one fails, just call
update_list()
again (but note that the 1-second delay will be in effect).