Jquery. form. js cannot solve the connection timeout (timeout) problem. connecttimeout times out.
Recently, when using jquery. form. js to submit a form containing files, we encountered a problem: when the network speed is slow and we set timeout, for example:
Var options = {timeout: 3000 // limit the request time. The request jumps out after 3 seconds}
Our page will die here and paste the result returned by the F12 developer tool:
At this point, we do not have a callback function to handle errors. In the Baidu example, we only have these two callback functions:
BeforeSubmit: showRequest, // callback function before submission
Success: showResponse, // callback function after submission
Therefore, I went to the official website to view the API. The official website: http://malsup.com/jquery/form/javasoptions-object, and found the callback for handling the error:
errorCallback function to be invoked upon error.
So my options is written as follows:
Var options = {beforeSubmit: showRequest, // callback function success: showResponse before submission, // callback function error: showError after submission, // error callback function after submission
Timeout: 3000 // limit the request time. When the request exceeds 3 seconds, the request jumps out.
}
The callback function is written as follows:
Function showError (responseText, statusText) {if (statusText = 'timeout') {layer. msg ("the server is busy. Please try again later! ", {Icon: 5, time: 1500}); return ;}}
This is my solution. I don't know if it solves your problem?