简体   繁体   English

设置超时jQuery.load()

[英]Setting timeout jQuery.load()

I have an event that when clicked initiates a jQuery load(). 我有一个事件,当单击该事件会启动jQuery load()。 The load passes several MB of POST data. 负载传递了数MB的POST数据。 I am getting aborted errors. 我正在中止错误。 How can I set the timeout? 如何设置超时时间?

 toggleModalLoading();
 $("#ele").load('http://site.com/script.php',{
               'data' : postData },
                function(e) {
                      toggleModalLoading();
                });

The .load() call is really just a convenient shorthand. .load()调用实际上只是一个便捷的简写。 You could set global ajax options before the .load() call. 您可以在.load()调用之前设置全局ajax选项 If that's not viable, you'll have to use the lower-level API . 如果这样做不可行,则必须使用较低级别的API Either way, you want the timeout ajax option: 无论哪种方式,您都需要timeout ajax选项:

$.ajax('http://site.com/script.php', {
   data: postData,
   timeout: 1000, // 1000 ms
   success: function (data) {
       $('#ele').html(data);
       toggleModalLoading();
   } 
});

set the timeout for the Ajax calls. 设置Ajax调用的超时。

$.ajaxSetup({
    timeout: 30000
});

If the server is causing it to stop, look at the settings in the php ini file. 如果服务器导致其停止,请查看php ini文件中的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM