jquery Ajax Application Instance code

Source: Internet
Author: User
Tags visibility

jquery Ajax Application Instance code
/*
Ajax sends data to a page

$.post (' save.cgi ', {
Text: ' My string ',
Number:23
}, function () {
Alert (' Your data has been saved. ');
});


If you do need to write some complex Ajax scripts, you need to use the $.ajax () function. You can specify that XML, script, HTML, or json,jquery will automatically prepare the appropriate results for the callback function so that you can use the result immediately. You can also specify Beforesend, error, success, or complete callback functions to provide users with more feedback about the Ajax experience. In addition, there are other parameters available that you can use to set the timeout for Ajax requests, or to set the status of the page "last modified"

*/
Super Simple jquery Ajax application

function Visit_build () {
var myclasses = new Ajax (' Visit!build.action ', {
Method: ' Post ',
data:{
Id:this_bid
},
Oncomplete:function (response) {
}
). request ();
}

Here is a validation mailbox address mailbox Authentication instance with multiple parameters

function Nactactivity_submit () {
var aid = $ (' aid '). Value;
var name = $ (' a_name '). Value;
var mobile = $ (' mobile '). Value;
var email = $ (' email '). Value;
var address = $ (' address '). Value;
var email_p =/^ ([a-za-z0-9_-]) +@ ([a-za-z0-9_-]) + (. [ A-za-z0-9_-]) +/;
var tel_p =/^[0-9-]+$/;
if (name.length>0 && mobile.length==11 && email.length>0 && email_p.test (email) & & Tel_p.test (MOBILE)) {
var myclasses = new Ajax (' Activity!submitnact.action ', {
Method: ' Post ',
data:{
Id:aid,
Name:name,
Mobile:mobile,
Email:email,
Address:address
},
Oncomplete:function (response) {
$ (' Massage_box '). sethtml (response);
$ (' Massage_box '). SetStyle (' width ', 810);
$ (' Massage_box '). SetStyle (' height ', 500);
$ (' Massage_box '). SetStyle (' visibility ', ' visible ');
$ (' mask '). SetStyle (' visibility ', ' visible ');
$ (' Massage_box '). SetStyle (' left ', (980-a+200)/2);
$ (' Massage_box '). SetStyle (' Top ', (window.screen.height-650)/2);
}
). request ();
}else{
Alert (' Please fill in complete, name, mobile phone number, mailbox are required ');
}
}

/*
Working with XML documents

$.ajax () makes Ajax simpler by complexity

$.ajax ({
URL: ' Document.xml ',
Type: ' Get ',
DataType: ' xml ',
timeout:1000,
Error:function () {
Alert (' Error loading XML document ');
},
Success:function (XML) {
Do something with XML
}
});



When the success callback function returns an XML document, you can use jquery to retrieve the XML document in the same way that it retrieves an HTML document. This makes it fairly easy to process XML documents and integrates content and data into your Web site

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.