jquery cross-Domain AJAX requests

Source: Internet
Author: User

Sonp principle:
First register a callback with the client and then pass the callback name to the server.

At this point, the server becomes JSON data.
Then, in JavaScript syntax, a function is generated, and the function name is the parameter Jsonp passed up.

Finally, the JSON data is placed directly into the function in the form of a parameter, so that a document of JS syntax is generated and returned to the client.

The client browser parses the script tag and executes the returned JavaScript document, where the data is passed in as a parameter to the client's pre-defined callback function. (Dynamic execution callback function)

One

function Getsitedata (Idsite, Lastminutes,index) {
$.ajax ({
Cache:false,
Type: "Get",
URL: "Http://baidu.com/index.php?module=API&method=Live.getCounters&format=JSON&token_auth= 5450d4c72203c278e6ff67cd40bdd9ac&idsite= "+ idsite +" &lastminutes= "+ lastminutes +" &jsoncallback=? ",
DataType: "Jsonp",
Success:function (data) {
$ ("#readvisits" + Index). Text (data[0].visits);
$ ("#readvisitors" + Index). Text (data[0].visitors);
}
})
}

Two

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.