jquery $.ajax related usage sharing _jquery

Source: Internet
Author: User
Copy Code code as follows:

$.ajax ({
Type: "Get",
URL: "Services/efservice.svc/members",
Data: "{}",
ContentType: "Application/json; Charset=utf-8 ",
DataType: "JSON",
Success:function (data) {
Play with returned data in JSON format
},
Error:function (msg) {
Alert (msg);
}
});

Global events are triggered every time an AJAX request is made, and it broadcasts to all elements in the DOM, and the script loaded in the Getscript () example above is a global Ajax event. Global events can be defined as follows:
Copy Code code as follows:

$ ("#loading"). Ajaxstart (function () {
$ (this). Show ();
});

We can disable global events at a specific request, as long as you set the global option:
Copy Code code as follows:

$.ajax ({
URL: "Test.html",
global:false,//disables global Ajax events. // ... });

The following is a complete list of Ajax events that are officially given by jquery:
Ajaxstart (Global Event)
This event is broadcast if a AJAX request is started and no other AJAX requests are currently running.
beforesend (local Event)
This event, which are triggered before an Ajax request is started, allows your to modify the XMLHttpRequest object (setting Additional headers, if need be.)
ajaxsend (Global Event)
This global event was also triggered before the request is run.
success (local Event)
This event is only called if the ' request was ' successful (no errors from the server and no errors with the data).
ajaxsuccess (Global Event)
This event is also only called if the request was successful.
error (Local Event)
This is the ' only called if ' occurred with the ' request (you can never have both an error and a success callback W ith a request).
ajaxerror (Global Event)
This global event behaves the same as the local error event.
complete (local Event)
This event is called regardless of if the request was successful, or not. You'll always receive a complete callback, even for synchronous requests.
Ajaxcomplete (Global Event)
This event behaves the same as the complete event and would be triggered every time of Ajax request finishes.
ajaxstop (Global Event)
This global event are triggered if there are no more Ajax requests being processed.
Jquery.ajaxsetup (Options): Sets the global AJAX default option.
Set AJAX request default address is "/xmlhttp/", prohibit triggering global Ajax event, use POST instead of default get method. Subsequent AJAX requests no longer have any option parameters set.
JQuery Code:
Copy Code code as follows:

$.ajaxsetup ({
URL: "/xmlhttp/",
Global:false,
Type: "POST"
});
$.ajax ({data:mydata});


If you specify an HTML type, any embedded JavaScript executes before the HTML is returned as a string. Similarly, if you specify a script type, the server-side generated JavaScript is executed first, and then the script is returned as a text data.
JSON data is a structured data that can be easily parsed by JavaScript. If you get a data file that resides on a remote server (the domain name is different, that is, you get the data across the domain), you need to use the JSONP type. Using this type, a query string parameter is created callback=? , this parameter is appended to the URL of the request. The server side should precede the JSON data with the callback function name in order to complete a valid JSONP request. If you want to specify the parameter name of the callback function to replace the default callback, you can set the JSONP parameter of the $.ajax ().    

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.