jquery Ajax and Getjson get JSON data across domains __JS

Source: Internet
Author: User

Many developers use jquery to interact with the front-end and server side of the data, so it's easy to assume that using jquery on the front end can read any site's data. Recently in the development, because to and a third party company's data sharing, because of the consideration of more than the resources of the server, so decided to directly in the HTML data read, do not go to the server side of the relay. And then it just happens to be a problem with browser-side Cross-domain access.

Cross-domain security restrictions are the browser-side, the server side does not exist cross-domain security restrictions.

There are two commonly used methods for browser-side Cross-domain access:

1, through jquery Ajax to cross domain, this is actually adopted JSONP way to achieve.

JSONP is an abbreviation of the English JSON with padding. It allows script tags to be generated on the server side to return to the client, that is, dynamically generating JavaScript tags, which enable data reading through JavaScript callback.

HTML page End sample code:?

1 2 3 4 5 6 7 8 9 A //First introduce jquery's JS packet jquery (docume NT). Ready (function () {     $.ajax ({         type: "Get ",//jquey is not supported by post way Cross-domain          Async:false,           URL: "Http://api.taobao.com/apitools/ajax_props.do",//cross domain request URL           dataType: "Jsonp",         //pass to request handler, Parameter name used to obtain the name of the JSONP callback function (default: Callback)          JSONP: "Jsoncallback",          //Custom JSONP callback function name, default to jquery automatically generated random function name           jsonpcallback:
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.