How does ajax set timeout (an action is executed twice)? ajaxaction

Source: Internet
Author: User

How does ajax set timeout (an action is executed twice)? ajaxaction

Today, during the test project, we found that an action was executed twice. This operation took about five minutes to complete. The project environment was apache2 + tomcat6.0.

Several timeout settings have been found during online search:

1. Set the ajax syntax in milliseconds, for example:

$. Ajax ({url: XXX, timeout: 600000, type: 'post', data :{}, error: function () {show_fail_meg ("failed to start the system! ");}});

2. tomcat configuration server. xml in milliseconds

Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>

3. apache configuration file httpd. conf, in seconds

# # Timeout: The number of seconds before receives and sends time out. # Timeout 60

After the modification, it was found that it was still not effective and finally located in the mod_jk module,

Mod_jk, short for JK, is a plug-in module of the Apache server. It provides Apache or IIS server with the ability to process JSP/Servlet.

That is to say, JK settings may overwrite the settings of apache2, tomcat, and ajax.

The configuration file/etc/httpd/conf/workers. properties of JK is as follows:

worker.master.socket_timeout=300

The number is exactly 5 minutes, which is consistent with the exception. Restart After the exception is increased. It is normal!


Ajax times out. The jump function is executed completely.

You sent a request to the background in Ajax and processed it for a long time in the background. ajax is impatient and a timeout prompt is displayed. Can I understand this?

In struts2, jsp pages access action through ajax. How does action return a json data to this jsp page,

Background:

Public class pageAction extends ActionSupport {
Private String username;
Private String password;
Private String cmd;

Public String execute (){
String result = "";
String message = "";
// Create a stream
PrintWriter out = null;
// Create a json object
JSONObject json = new JSONObject ();
Cmd = ServletActionContext. getRequest (). getParameter ("cmd ");
Username = ServletActionContext. getRequest (). getParameter ("username ");
Password = ServletActionContext. getRequest (). getParameter ("password ");
// System. out. println ("username:" + username + ", password:" + password );
If ("admin". equals (username) & "admin". equals (password )){
Json. put ("content", "true ");
} Else {
Json. put ("content", "incorrect account or password! ");
}
Out. write (json. toString ());
Return SUCCESS;
}
}

Front-end:

<Script type = "text/javascript">
Function checkAnswer (){
// Obtain the entered account and password
Var username = document. getElementById ("username"). value;
Var password = document. getElementById ("password"). value;
DataStr = {
Checkname: username,
Checkpass: password
};
JQuery
. Ajax ({
Type: "POST ",
Url: "ajax/checkAnswer. action? Temp = "+ Math. random (),
Data: dataStr,
DataType: "json ",
Success: function (root ){
If (& quo... the remaining full text>
 

Related Article

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.