Setting jQuery.load () timeout

I have an event that when clicked triggers the loading of jQuery (). The load goes through several MB of POST data. I get interrupted errors. How to set a timeout?

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

Calling .load() is just a convenient shorthand. You can set global ajax parameters before calling .load() . If this is not viable, you will have to use the lower level API . In any case, you need the timeout ajax option:

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

set timeout for Ajax calls.

 $.ajaxSetup({ timeout: 30000 }); 

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

+1
source

Source: https://habr.com/ru/post/1437868/


All Articles