about using $. Selection and viewing of Ajax () control buttons

Source: Internet
Author: User

Front-end JSP page code:

Please select a version:
<br/>
<div>
Push version: <input type= "button" id= "post1" class = "ver" value= "Push"/><br/>
Response version: <input type= "button" id= "post2" class = "ver" value= "Response"/><br/>
Current version view: <button id= "Post3" value= "VerCheck" > View </button>
</div>
<br/>
<br/>
<div id = "Result" ></div>
<script src= "<%=path%>/js/jquery.min.js" ></script>
<script src= "<%=path%>/js/verselect.js" ></script>

JS Control Code:

$ (function () {
$ (' #post1 '). Click (function () {
Alert (1);
$ (' #result '). innerhtml= "";
var vers = "0";
$.ajax ({
DataType: "HTML",
Type: ' POST ',
url:g.basepath+ '/verselect.do ',
Data: {
Vers
},
Success:function (data) {
$ (' #result '). HTML (data)
}
});
})
$ (' #post2 '). Click (function () {
Alert (2);
$ (' #result '). innerhtml= "";
var vers = "1";
$.ajax ({
DataType: "HTML",
Type: ' POST ',
url:g.basepath+ '/verselect.do ',
Data: {
Vers
},
Success:function (data) {
$ (' #result '). HTML (data)
}
});
})
$ (' #post3 '). Click (function () {
Alert (3);
$ (' #result '). innerhtml= "";
var ver = $ (' #post3 '). Val ();
$.ajax ({
DataType: "HTML",
Type: ' POST ',
url:g.basepath+ '/verselect.do ',
Data: {
Ver
},
Success:function (data) {
$ (' #result '). HTML (data)
}
});
})
})

Background request processing, where post submission requests are used

Import java.io.IOException;
Import Java.util.concurrent.atomic.AtomicBoolean;

Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;


public class Verselectservlet extends HttpServlet {

public static Version = FALSE;

@Override
protected void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
DoPost (request, response);
}

@Override
protected void DoPost (HttpServletRequest request,
HttpServletResponse response) throws Servletexception, IOException {
String vers = Request.getparameter ("vers");
if ("1". Equals (vers)) {
Response.getwriter (). Print ("Switched to current version");

Version = Ture;
}
if ("0". Equals (vers)) {
Response.getwriter (). Write ("Switched to current version");

Version = FALSE;

}
String ver = request.getparameter ("ver");
if ("VerCheck". Equals (ver)) {
if (!version) {
Response.getwriter (). Write ("Currently 0 version");
}
if (version) {
Response.getwriter (). Write ("Currently 1 version");
}
}
}
}

about using $. Selection and viewing of Ajax () control buttons

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.