jquery Ajax Get instance and detailed tutorial

Source: Internet
Author: User
Tags error code php tutorial

Jquery.get (URL, [data], [Callback (data, Textstatus, XMLHttpRequest)], [datatype])

Returns:xmlhttprequest

URL string that contains the URL of the request being sent.

The data map or string is sent to the server with the request.

Callback (data, Textstatus, XMLHttpRequest) If the request is successfully executed.

Datatypethe type of data is expected from the server.

This is an abbreviated AJAX feature, which is equivalent to:

$.ajax ({
Url:url,
Data:data,
Success:success,
Datatype:datatype
});


The tuning function successfully returns data passing, which will be an XML root element, a text string, a Web effects file, or a JSON object based on the MIME type of the response. It also passes the response text state.

In jquery 1.4, the successful callback function is also passed through the XMLHttpRequest object.

Most implementations will specify a successful handler:

$.get (' ajax/test.html ', function (data) {
$ ('. Result '). HTML (data);
Alert (' Load was performed. ');
});

This example gets the HTML fragment on the requested page and inserts it.

Additional considerations:
Due to browser security restrictions, most "Ajax" requirements are based on the same Origin policy; Request cannot successfully retrieve data from a different domain, subdomain or protocol.
If a jquery.get () request returns an error code, it will silently fail unless the script also calls the global. Ajaxerror () method.
Script and Jsonp form requests are not limited by the homology policy.
Example:
For example: a Web page that requests a test.php tutorial, but ignores the return result.

$.get ("test.php");

For example, request a test.php page and follow some extra data (while ignoring the return result).

$.get ("test.php", {name: "John", Time: "2pm"});

For example, an array of data is passed to the server (and the return result is ignored).

$.get ("test.php", {' choices[] ': ["Jon", "Susan"]});

For example, alert is the result of the request test.php (HTML or XML, and what is returned).

$.get ("test.php", function (data) {
Alert ("Data loaded:" + data);
});

For example: Alert results from the extra load test.cgi from the same data request (HTML or XML is returned what is different).

$.get ("test.cgi", {name: "John", Time: "2pm"},
function (data) {
Alert ("Data loaded:" + 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.