Ajax Cross-domain operation has been a difficult problem, now the main solutions are:
1, JSONP (need to support on the server side)
2, IFrame (can only operate in the subdomain)
3, page agent (this a little omnipotent)
4, Access-control-allow-origin (new browser support, need to set header on the server side)
Today, kid. Provides a way to use flash for cross-domain operations. Many weeks, in fact, the scope of the operation of Flash is also limited, but, Flash's cross-domain configuration than simple, only to be placed in the site root directory crossdomain.xml can be. As for the use of crossdomain.xml, you can read this article: http://www.jb51.net/article/25485.htm this article.
For this series of operations, the kid has been encapsulated as a plug-in form of jquery, with the download address attached at the end of the article.
How to use:
1, in the page to introduce jquery and ajaxf.js files.
2, insert the following code on the page. First installs the Flash to the page.
Copy Code code as follows:
$ (document). Ready (function () {
$.ajaxf.install ('/files/zsea/flash4ajax.swf ');
});
3. Call method to get remote data.
The following is a detailed list of the methods that the plugin provides:
$.ajaxf.install (Swfpath)
Install Flash to the page, you can specify the path of the flash.
$.ajaxf.ready (function () {})
A function that is executed after the Flash has finished loading.
$.ajaxf.isready ()
Returns whether Flash has completed loading. The return value is Boolean
$.ajaxf.ajax (P)
Native Ajax invocation Support, p is an object, including: Callback, callback function, type, method type, support Json,text,xml,script;url, read the data address; method, request methods, support Get,post;data, The sent data; ContentType, the requested ContentType header, the Header,object object, the additional request header.
$.ajaxf.get (URL, data, callback, type)
Getting data from a get way
$.ajaxf.post (URL, data, callback, type)
Get data by post
The following a few people look at the name to know that the letter is not more to explain the meaning
$.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)
Here's how to get the HTML code to get the cool home page.
Copy Code code as follows:
<script type= "Text/javascript" >
$ (document). Ready (function () {
$.ajaxf.install ('/files/zsea/flash4ajax.swf ');
$ ("#fdemo_get"). Click (function () {
$.ajaxf.gettext ("http://www.youku.com/", "", function (r) {
$ ("#fdemo"). Val (R);
});
});
});
</script>
<textarea id= ' Fdemo ' style= ' width:500px; height:300px; ' ></textarea>
<br/>
<input type= "button" value= "Fetch data" id= ' Fdemo_get '/>
Unfortunately, the kid doesn't know how to run the code on the page in the garden. Only friends have tested themselves.
Download Address:/201012/yuanma/ajaxf.rar