JQuery Ajax-ajax () method

Source: Internet
Author: User

1.jsp page

functionOnsaveclick (BTN) {//Save$.ajax ({URL:"", type:"POST", Data: $ ("#form"). Serialize (), the data sent to the server must be in the Key/value format for example: {"AA": $ ("#id"). Val ()}, DataType:' JSON ', the data type returned by the server success:function(data) {if(data.success = = ' true ') {alert (' Operation succeeded! ');                        } Else{alert (' Operation failed: ' +data.msg); }}, Error:function() {alert ("Network Error");    }                }); }

2. Backstage (two kinds of return page data)

// Save     @RequestMapping ("/save")     @ResponseBody     public  String Save (User user) {           Try  {             //Operation return "{\" success\ ": \" true\ "}";          Catch (Exception e) {             e.printstacktrace ();              return "{\" success\ ": \" false\ ", \" msg\ ": \" "+ e.getmessage () +" \ "}";         }     }
//Save@RequestMapping (Value= "/save") @ResponseBody PublicObject Save (user user){Map<String,Object> map =NewHashmap<string, object>(); Try{String ID=meetingservice.save (form). GetId (); Map.put ("Success",true);        }Catch(Exception e) { //Operation Map.put ("Success",false); Map.put ("MSG", E.getmessage ()); }        returnmap; }

JQuery Ajax-ajax () method

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.