Jsp+jquery using AJAX to invoke JSON implementation _jsp programming

Source: Internet
Author: User

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.

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.