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: |