JS and jquery Learn--03.ajax small detail notes

Source: Internet
Author: User

$(function() {    //alert (2); Give more hints and develop a habit test    varmao=[{"Zhi1": "Mao1", "Zhi2": "Mao2"},{"Zhi3": "Mao3", "Zhi3": "Mao3"}];//This is the object array.//Put the value to pass$.ajax ({"url": "Maojiale",//Path"Type": "Post",//Way Post/get"Data": mao[1],//give subscript, otherwise the servlet page cannot be based on the key, value"DataType": "JSON",//define the data format of the reverse back"Success": HD,//callback function"Error":function() {alert ("AJAX Error!!!" ");     }            }); //callback function, KK, an array of objects coming from the Servlet page, or objects, values, etc., note: This can only have one parameter    functionHD (KK) {//Each loop output$ (KK). each (function(i) {$ ("#mao"). Append ("id" + This. id+ "Name is" + This. name+ "Gender" + This. Sex);                }); }});

Below is

The servlet page code is then combined to implement the value of the Ajax pass value
    protected voidDoget (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {doPost (request, response); }    protected voidDoPost (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {//Set character encodingRequest.setcharacterencoding ("Utf-8"); Response.setcharacterencoding ("Utf-8"); //Output ObjectPrintWriter out=Response.getwriter (); //fetch the value of the JSP pageString qu=request.getparameter ("Zhi3"); System.out.println ("Value is" +qu); List<shiti> list=NewArraylist<shiti> ();//cannot generally return objects to go, so to convert the format to, JSON formatList.add (NewShiti (1, "Zhang San", "male")); List.add (NewShiti (2, "John Doe", "male")); List.add (NewShiti (3, "I Dare", "female")); String mm=json.tojsonstring (list);//fastjsonn converting formats with jar packet serialization//Output Object Call method pass value back to JSP pageOut.print (mm); }
Because the callback function can only put one, so Out.print () also put an object,   so, in the callback function, the ' original ' parameter arbitrarily defined "KK"




JS and jquery Learn--03.ajax small detail notes

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.