Setting timeout jQuery.load()

£可爱£侵袭症+ 提交于 2019-12-22 08:43:49

问题


I have an event that when clicked initiates a jQuery load(). The load passes several MB of POST data. I am getting aborted errors. How can I set the timeout?

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

回答1:


The .load() call is really just a convenient shorthand. You could set global ajax options before the .load() call. If that's not viable, you'll have to use the lower-level API. Either way, you want the timeout ajax option:

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



回答2:


set the timeout for the Ajax calls.

$.ajaxSetup({
    timeout: 30000
});

If the server is causing it to stop, look at the settings in the php ini file.



来源:https://stackoverflow.com/questions/12734444/setting-timeout-jquery-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!