Four Ajax request method

AJAX is a technology to exchange data with the server, you can update a part of a web page supplement in the case of the entire page. Commonly use the following four:

1. $. Ajax () returns the XMLHttpRequest object that it creates.

$ .Ajax () only one parameter: the parameter key / value object that contains the configuration and callback information. Detailed parameter options below.

If you specify the dataType option, make sure the server returns the correct MIME information (such as xml return "text / xml").
Save data to the server, display information on success.
.ajax $ ({
type: "POST",
dataType: "HTML",
URL: 'request address',
Data: parameters,
Success: function (Data) {// Data callback information
! IF (Data = "") {
Console .log (Data);
} the else {

}
}
});

2. Loading information request by the remote Http Get

This is a simple GET request to replace the function of the complex $ .ajax. The callback function can be invoked when the request is successful. If you need to execute the function when an error occurs, use $ .ajax.
$ .get ( "request address", {name: "John" , time: "2pm"}, // argument list
function (Data) {
Alert (Data);
});

3. Loading information request by the remote HTTP POST.

This is a simple function of the POST request to replace the complex $ .ajax. The callback function can be invoked when the request is successful. If you need to execute the function when an error occurs, use $ .ajax.
$ .post ( "request address" {parameter list, using the key-value pairs}, function (Data) {
IF (Data == "OK") {
Alert ( "successfully!");
}
})

4. Loading JSON data request through HTTP GET.

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",{参数列表}
function(data){

});

Guess you like

Origin www.cnblogs.com/-Neo/p/11548784.html