设置超时jQuery.load()jQuery、load

由网友(挥霍着青春)分享简介:我有一个事件,点击时启动一个jQuery的load()。负载通过几MB的POST数据。我正在中止错误。如何设置超时?toggleModalLoading();$(#ele).load('http://site.com/script.php',{'数据':POSTDATA},功能(E){toggleModalLoadin...

我有一个事件,点击时启动一个jQuery的load()。负载通过几MB的POST数据。我正在中止错误。如何设置超时?

  toggleModalLoading();
 $(#ele).load('http://site.com/script.php',{
               '数据':POSTDATA},
                功能(E){
                      toggleModalLoading();
                });
 

解决方案

.load()通话仅仅是一个方便的速记。你可以设置全局AJAX选项中的 .load()通话。如果这是不可行的,你将不得不使用较低级别的API 。无论哪种方式,你想要的暂停 AJAX选项:

  $。阿贾克斯('http://site.com/script.php',{
   数据:POSTDATA,
   超时:1000 // 1000毫秒
   成功:功能(数据){
       $('#ELE)HTML(数据)。
       toggleModalLoading();
   }
});
 

请教一下,在jquery里能够先创建一个div,再在该div里使用load方法载入页面吗

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();
                });

解决方案

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();
   } 
});