Setting timeout jQuery.load()
10,220
Solution 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();
}
});
Solution 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.
Author by
user974896
Updated on August 21, 2022Comments
-
user974896 over 1 year
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(); });
-
Matt Ball over 11 yearsSure. Anything is possible. Wire up an
error
handler and see what's going on. -
user974896 over 11 yearsJust did. console.log("Text is: " + text + "Err is " + err); in my error: function(jqXHR, text, err) {} function. I am getting "Text is error" with no status code.
-
epascarello over 11 yearsYes, did you look at the error returned? Did you change the ini file to handle larger files?
-
user974896 over 11 yearsI set the max post size, max upload size, and execution time well above the limits. Still an issue. It's not a file in terms of multipart/form-data. It's a base64 encoded string that is 10MB.
-
user974896 over 11 yearsThe server can handle the request as I manually POSTED the data. jQuery is choking