7. jquery Function Learning (Ajax part)

Source: Internet
Author: User

 

Function: $. Ajax (properties)
Function: access a remote page with an HTTP request
Return Value: XMLHttpRequest
Parameters;
(String) URL request address,
(String) type request type ("get", "Post ")
(String) datatype: Data Type returned from the server ("XML", "html", "script", "JSON ")
(Boolean) ifmodified: determines whether the returned content is changed based on the last-modified header.
(Number) Timeout: Request timeout
(Boolean) Global: Specifies whether the request causes a global Ajax event. The default value is true.
(Function) error: error handling function
(Function) Complete: The processing function after the request is completed.
(Object | string) data: data sent to the server
(String) contenttype: Default Value: "application/X-WWW-form-urlencoded"
(Boolean) processdata: the data transmitted to the server is converted to the query string by default to apply the default value "application/X-WWW-form-urlencoded"
If you want to transmit data using domdocuments, set this option to false.
(Boolean) aysnc: whether to transmit data asynchronously. The default value is true.
(Function) beforesend: The response function before the request.
Example:
Load and execute a Javascript file.

Jquery code
$. Ajax ({
Type: "Get ",
URL: "test. js ",
Datatype: "script"
})

Save some data to the server and configure y the user once its complete.

Jquery code
$. Ajax ({
Type: "Post ",
URL: "Some. php ",
Data: "name = John& Location= Boston ",
Success: function (MSG ){
Alert ("data saved:" + MSG );
}
});

Jquery code
VaR html = $. Ajax ({
URL: "Some. php ",
Async: false
}). Responsetext;

Jquery code
VaR xmldocument = [create XML document];
$. Ajax ({
URL: "Page. php ",
Processdata: false,
Data: xmldocument,
Success: handleresponse
});

 

 

Function: $. ajaxsetup (settings), $. ajaxtimeout (time)
Function: Set Request parameters.
Return: Undefined
Example:
$. Ajaxsetup ({
URL: "/XMLHTTP /",
Global: false,
Type: "Post"
});
$. Ajaxtimeout (5000 );

 

 

Function: $. Get (URL, Params, callback), $. getifmodified (URL, Params, callback ),
$. Getjson (URL, Params, callback), $. getscript (URL, callback)
Function: submit data in get mode.
Example:
$. Get ("test. cgi ",
{Name: "John", time: "2 "},
Function (data ){
Alert ("data loaded:" + data );
}
);

 

 

Function: $. Post (URL, Params, callback)
Function: submit data in post mode.
Example:
$. Post ("test. cgi ",
{Name: "John", time: "2 "},
Function (data ){
Alert ("data loaded:" + data );
}
);

 

 

Function: ajaxcomplete (callback), ajaxcomplete (callback), ajaxsend (callback)
Ajaxstart (callback), ajaxstop (callback), ajaxsuccess (callback)
Function: various response processing functions when the XMLHttpRequest status changes
Example:
$ ("# MSG"). ajaxcomplete (function (request, settings ){
$ (This). append (" < Li > Request complete. </ Li > ");
});
$ ("# MSG"). ajaxsuccess (function (request, settings ){
$ (This). append (" < Li > Successful request! </ Li > ");
});
$ ("# Loading"). ajaxstop (function (){
$ (This). Hide ();
});
$ ("# MSG"). ajaxsend (function (request, settings ){
$ (This). append (" < Li > Starting request at "+ settings. url +" </ Li > ");
});

 

 

Function: load (URL, Params, callback), loadifmodified (URL, Params, callback)
Function: loads HTML content.
Return: jquery object
Parameter: Same as the get and post methods.
Example:
Jquery code
$ ("# Feeds"). Load ("feeds.html ");
Before
< Div ID = "Feeds" > </ Div >
Result:
< Div ID = "Feeds" > < B > 45 </ B > Feeds found. </ Div >

Jquery code
$ ("# Feeds"). Load ("feeds.html ",
{Limit: 25 },
Function () {alert ("the last 25 entries in the feed have been loaded ");}

 

 

Function: serialize ()
Function: serialize form elements and values to strings.
Return Value: String
Example:
Jquery code
$ ("Input [@ type = text]"). serialize ();
Before
< Input Type = 'Text' Name = 'Name' Value = 'John' />
< Input Type = 'Text' Name = 'Location' Value = 'Boston '/
Result
Name = John & location = Boston
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.