I encountered a cross-domain problem two days ago, which can be solved using jsonp. (http://www.jb51.net/article/57889.htm)
Recently sorted it out:
1.jsonp.
Ajax request, dataType is jsonp. This form requires the request to be adjusted on the server side to return callback([json-object]). If the server returns a normal json object. Then when debugging, the "Uncaught SyntaxError: Unexpected token" error will be reported in the chrome browser console; the "SyntaxError: missing; before statement" error will be reported in the firefox browser console.
2.iframe cross-domain.
Add an iframe element to the page. When you need to call a get request, set the src of the iframe to the url of the get request to initiate the get request call.
The iframe method is stronger than jsonp. In addition to processing http requests, it can also implement js calls across domains.
3. src attribute processing of script elements
The src attribute of iframe, img, style, script and other elements can directly request resources from different domains. jsonp is a simple implementation of using script tags to request resources across domains, so this is essentially the same as jsonp and also requires server-side request return callback... form.
4. Use get processing on the server.
For business that does not have rigid requirements for front-end processing, you can encapsulate it on the server side and then initiate a call on the server side, so that cross-domain problems can be solved. Then depending on whether the request is sent out or whether the return value needs to be obtained, the code uses synchronous or asynchronous mode.
5.flash跨域
过于尖端了==,再研究
总结:以上5种方法就是常见的解决js跨域问题的处理方法了,最后一种比较高端,等我研究清楚了再补上吧。