This example describes the implementation of Jsp+jquery using AJAX to invoke JSON. Share to everyone for your reference, specific as follows:
Front desk:
<script type= "Text/javascript" src= "jquery-1.5.1.min.js" ></script>
<script type= "text/" JavaScript ">
//test
function Test (UID)
{
If confirm (" Determines whether the user is manipulating "+uid+"?) )
{
var date = new Date ();
var param = {Uid:uid};
Jquery.get ("test.jsp?para=" + date, param,
function (data) {
if (data!= null)
{
var result = Data.result;
Alert ("data===" +data);
if (result = = 1)
{
alert ("Operation failed");
}
if (result = = 0)
{
alert ("Operation failed.") ");
Document.location.href = document.location;
Window.location.reload ();}}}
);
} </script>
<a href= "javascript:void (0);" onclick= "Test (111111111111111111);" >submit</a>
Background:
TEST.JSP:
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><% response.setcontenttype
(" Application/x-json;charset=utf-8 ");
String uid=request.getparameter ("UID");
int ret=0;
String result = "{\" result\ ":" + ret + "}";
Out.print (result);
%>
Note: Returns the JSON format
such as {"Result": 0}
Need to set:
Copy Code code as follows:
Response.setcontenttype ("Application/x-json;charset=utf-8");
I hope this article will help you with JSP program design.