Home >Web Front-end >JS Tutorial >Implementation method of using Flash to read cross-domain data in Ajax_javascript skills

Implementation method of using Flash to read cross-domain data in Ajax_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:14:571026browse

Cross-domain operation of Ajax has always been a problem. The current main solutions are:
 1. JSONP (needs to be supported on the server side)
 2. IFrame (can only operate between subdomains)
3. Page proxy (this is a bit universal)
4. Access-Control-Allow-Origin (supported by new browsers, you need to set the Header on the server side)
Today, I provide another way to use Flash for cross-domain operations. method. As we all know, there are actually limitations to Flash's cross-domain operations. However, Flash's cross-domain configuration is relatively simple. You only need to place crossdomain.xml in the root directory of the site. As for the usage of crossdomain.xml, you can read this article: http://www.jb51.net/article/25485.htmThis article.
For this series of operations, I have encapsulated it in the form of a jQuery plug-in, and the download address will be attached at the end of the article.
How to use:
1. Introduce jQuery and ajaxf.js files into the page.
2. Insert the following code on the page. First install Flash into the page.

Copy code The code is as follows:

$(document).ready(function() {
$.ajaxf.install('/Files/zsea/flash4ajax.swf');
});

 3. Call the method to obtain remote data.

Let’s talk about the methods provided by the plug-in in detail:
$.ajaxf.install(swfpath)
To install Flash to the page, you can specify the path of Flash.
 $.ajaxf.ready(function(){})
 The function executed after Flash is loaded.
  $.ajaxf.isReady()
Returns whether Flash has been loaded. The return value is Boolean
  $.ajaxf.ajax(p)
  Native ajax call support, p is an object, including: callback, callback function; type, method type, supports json, text, xml, script; url, the address to read the data; method, the request method, supports get, post; data, the data sent; contentType, the contentType header of the request; header, Object object, additional request headers.
  $.ajaxf.get(url, data, callback, type)
  Get data through get method
$.ajaxf.post(url, data, callback, type)
Get data through post method
Everyone knows the meaning of the following names just by looking at them, so I won’t explain them too much
$.ajaxf.getText(url, data, callback)
$.ajaxf.getJSON(url, data, callback)
$.ajaxf.getScript(url, data, callback)
$.ajaxf.postJSON(url, data, callback)
$.ajaxf.postText(url, data, callback)

Let’s demonstrate how to obtain the HTML code for Youku’s homepage.
Copy code The code is as follows:








Unfortunately, I don't know how to run the code on the page in the garden. Only friends have tested it themselves.
Download address: /201012/yuanma/Ajaxf.rar
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn