Jquery Ajax Instance

Source: Internet
Author: User

//1.$.ajax asynchronous requests with JSON datavarAJ =$.ajax ({URL:' Productmanager_reverseupdate ',//Jump to Actiondata:{Selrollback:selrollback, Seloperatorscode:seloperatorscode, P Rovincecode:provincecode, Pass2:pass2}, type:' Post ', Cache:false, DataType:' JSON ', Success:function(data) {if(Data.msg = = "true" ){              //View ("Modified successfully!  "); Alert ("Modified successfully! ");          Window.location.reload (); }Else{view (data.msg); }}, Error:function() {            //view ("Exception!  "); Alert ("Exception! "); }  });//2.$.ajax asynchronous requests that serialize the contents of a table to a stringfunctionnotips () {varFormparam = $ ("#form1"). Serialize ();//Serialize table contents as strings$.ajax ({type:' Post ', URL:' Notice_notipsnotice ', Data:formparam, cache:false, DataType:' JSON ', Success:function(data) {}}); }  //3.$.ajax asynchronous requests for stitching URLsvaryz=$.ajax ({type:' Post ', URL:' validatepwd2_checkpwd2?password2= ' +Password2, data:{}, cache:false, DataType:' JSON ', Success:function(data) {if(Data.msg = = "false")//The server returns false, changing the value of ValidatePassword2 to Pwd2error, which is asynchronous and needs to consider the return time{textpassword2.html ("<font color= ' red ' > Business password is incorrect! </font> "); $("#validatePassword2"). Val ("Pwd2error").); CheckPassword2=false; return; }}, Error:function(){}  }); //4.$.ajax asynchronous request to splice data$.ajax ({URL:' <%=request.getcontextpath ()%>/kc/kc_checkmernameunique.action ', type:' Post ', Data:' Mername= ' +values, Async:false,//default is True asyncErrorfunction() {alert (' Error '); }, Success:function(data) {$ ("#"+divs). HTML (data); }});

I. General format of $.ajax

$.ajax ({

Type: ' POST ',

URL: URL ,

Data: data ,

Success: Success ,

DataType: dataType

});

Second, the parameter description of $.ajax

Parameter description

Url Necessary. Specifies which URL to send the request to.
Data Optional. The map or string value. Specifies the data that is sent to the server along with the request.
Success (data, Textstatus, JQXHR) Optional. The callback function to execute when the request succeeds.
DataType

Optional. Specifies the data type of the expected server response.

The default is to perform smart judgments (XML, JSON, script, or HTML).

three, $.ajax need to pay attention to some places:

There are three main ways of 1.data, HTML splicing, JSON array, form form is serialized by Serialize (), and no intelligent judgment is specified by datatype.

2.$.ajax only submits form in text mode, if the asynchronous commit contains <file> uploads are not passed over, you need to use Jquery.form.js $.ajaxsubmit


Reference Link: http://jun1986.iteye.com/blog/1399242

Jquery Ajax Instance

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.