About jquery using Get and Post methods

Source: Internet
Author: User

Recently, I found a colleague who wrote a piece of code (on the Import.jsp) page to write the following code:

<%

String action=request.getparameter ("action");
%>

<%
Pagemenustr + = "{E," + "import" + ", Javascript:onimp ();}";
%>
<div id= "Pagemenubar" style= "z-index:100;" ></div>
<%@ include file= "/vbase/pagemenu.jsp"%>

var i=0;

function Onimp () {

i++;
Jquery.get ("import.jsp", {action: "Imp", I: "I"},function (data) {
});
if (j==0) {
Alert ("In the import, please wait!");
Return
}
i=0;
Alert ("In the import, please wait!");
CheckStatus ();
}

}

Here Pagemenustr is the code used to generate the button.

Each time the system reboots, the first run of this method, can take out the value of the action is imp, and after many clicks on the button, the action value has become null.

And I changed the code to:

function Onimp () {
i++;
Jquery.post ("import.jsp", {action: "Imp", I: "I"},function (data) {
});
if (j==0) {
Alert ("In the import, please wait!");
Return
}
i=0;
Alert ("In the import, please wait!");
CheckStatus ();
}

After the Get method is changed to the Post method, the action can correctly value imp no matter how many times the button is clicked.

Here's a little detail:

Is the problem of using the I variable.

Cause I found it. Please see my another article on the difference between get and post.

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.