Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ajax get in jquery

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to use ajax get in jquery". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use ajax get in jquery" can help you solve the problem.

Jquery.get (url, [data], [callback (data, textstatus, xmlhttprequest)], [datatype])

Returns: xmlhttprequest

The url string containing the url request is sent.

Data map or string is sent to the server with the request.

Callback (data, textstatus, xmlhttprequest), if the request is executed successfully.

The datatypethe type of data is expected from the server.

This is an abbreviated ajax function, which is equivalent to:

$.ajax ({

Url: url

Data: data

Success: success

Datatype: datatype

})

The caller successfully returns the data passed, which will be a xml root element, a text string, a web page special 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 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 takes the html fragment on the requested page and inserts it.

Other considerations:

Due to browser security restrictions, most "ajax" requirements follow the same origin policy; requests cannot successfully retrieve data from a different domain, subdomain or protocol.

If a jquery.get () request returns an error code, it will fail quietly unless the script also calls for the world. The ajaxerror () method.

Scripts and requests in the form of jsonp are not subject to the same origin policy.

Example:

For example: the web page of the test.php tutorial is requested, but the result is ignored.

$.get ("test.php")

For example: request the page of test.php and follow some additional data (while ignoring the return result).

Get ("test.php", {name: "john", time: "2pm"})

For example, the data array is passed to the server (while ignoring the return result).

$.get ("test.php", {'choices []': ["jon", "susan"]})

For example: the result of alert from requesting test.php (html or xml, depending on what is returned).

$.get ("test.php", function (data) {

Alert ("data loaded:" + data)

})

For example: the result of alert's extra payload test.cgi from the same data request (what difference html or xml is returned).

$.get ("test.cgi", {name: "john", time: "2pm"}

Function (data) {

Alert ("data loaded:" + data)

})

This is the end of the content about "how to use ajax get in jquery". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report