How to Use Ajax

Source: Internet
Author: User

// 1. $. Ajax asynchronous request with JSON data
VaR AJ = $. Ajax ({
URL: 'productmanager _ reverseupdate', // jump to action
Data :{
Selrollback: selrollback,
Seloperatorscode: seloperatorscode,
Provincecode: 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 serialize asynchronous requests whose table content is a string
Function notips (){
VaR formparam = $ ("# form1"). serialize (); // serialize the table content as a string
$. Ajax ({
Type: 'post ',
URL: 'notice _ notipsnotice ',
Data: formparam,
Cache: false,
Datatype: 'json ',
Success: function (data ){
}
});
}


// 3. $. asynchronous request for URL Splicing
VaR YZ = $. Ajax ({
Type: 'post ',
URL: 'validatepwd2 _ checkpwd2? Password2 = '+ password2,
Data :{},
Cache: false,
Datatype: 'json ',
Success: function (data ){
If (data. MSG = "false") // if the server returns false, change the value of validatepassword2 to pwd2error. This is asynchronous and the return time must be considered.
{
Textpassword2.html ("<font color = 'red'> incorrect business password! </Font> ");
$ ("# Validatepassword2"). Val ("pwd2error ");
Checkpassword2 = false;
Return;
}
},
Error: function (){}
});


// 4. $. Ajax Concatenates the asynchronous request of data
$. Ajax ({
URL: '<% = request. getcontextpath () %>/KC/kc_checkmernameunique.action ',
Type: 'post ',
Data: 'mername = '+ values,
Async: false, // The default value is true asynchronous.
Error: function (){
Alert ('error ');
},
Success: function (data ){
$ ("#" Nvidivs#.html (data );
}
});

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.