Jquery. form. js cannot solve the connection timeout (timeout) problem. connecttimeout times out.

Source: Internet
Author: User

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?

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.