Some summary of the call between Java and Ajax

Source: Internet
Author: User


    1. Java returns an object, DataType: "Text";
      Java returns a JSON string, DataType: "JSON"; Page Json.parse () parsing, parsing JSON strings into JSON objects

      2,
      ContentType: "Application/json",//format sent to the server
      DataType: "Text",//server to the format of the page, if the JSON format with Json.parse () parsing, if it is an object on the text



3.
$.ajax ({
URL: "/test.do",
Data: {' x ': ' 001 '},
Async:false,
Type: "GET",
/* DataType: "Text", */
ContentType: "Application/json",
DataType: "JSON",
Success:function (data) {
Alert (data[' count ');
}
});


@RequestMapping (value = "Test.do")
@ResponseBody
Public map<string, object> test (httpservletrequest request, String x) {
Map<string, object> m = new hashmap<string, object> ();
M.put ("Count", 0);
return m;
}




4.
$.ajax ({
URL: "/test1.do",
data:{},
Async:false,
Type: "GET",
DataType: "JSON",
Success:function (data) {
var dataobj = json.parse (data);
alert (dataobj.1);
}
});


@RequestMapping (value = "Test1.do")
@ResponseBody
Public String Checkinfo (httpservletrequest request,httpservletresponse response) {
map<string, boolean> checkmap = new hashmap<string, boolean> ();
Checkmap.put ("1", false);
Checkmap.put ("2", true);
Jsonarray json = Jsonarray.fromobject (CHECKMAP);
return json.tostring ();
}

Some summary of the call between Java and Ajax

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.