How to implement cross-domain data reading using Flash in Ajax _javascript tips

Source: Internet
Author: User
Tags gettext object object
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
Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.