Cross-origin Data Reading using Flash in Ajax

Source: Internet
Author: User

Cross-origin operations of Ajax have always been a problem. Currently, the main solutions include:
1. JSONP (must be supported on the server)
2. IFrame (operations can only be performed between subdomains)
3. Page proxy (this is omnipotent)
4. Access-Control-Allow-Origin (supported by the new browser, you need to set the Header on the server)
Today, kiddie provides another method to use Flash for cross-origin operations. Flash cross-origin operations are restricted. However, the cross-origin configuration of Flash is relatively simple. You only need to place crossdomain. xml under the root directory of the site. As for crossdomain. xml usage, you can look at this article: http://www.jb51.net/article/25485.htm this article.
For this series of operations, the kiddies have been encapsulated as jQuery plug-ins and will be attached at the end of the article.
Usage:
1. Introduce jQuery and ajaxf. js files on the page.
2. Insert the following code on the page. First install Flash on the page. Copy codeThe Code is as follows: $ (document). ready (function (){
$. Ajaxf. install ('/Files/zsea/flash4ajax.swf ');
});

3. Call a method to obtain remote data.

The following describes in detail the methods provided by the plug-in:
$. Ajaxf. install (swfpath)
Install Flash on the page. You can specify the Flash path.
$. Ajaxf. ready (function (){})
The function executed after Flash is loaded.
$. Ajaxf. isReady ()
Whether the Flash has been loaded. Return Value: Boolean
$. Ajaxf. ajax (p)
Native ajax calls are supported. p is an object, including callback, callback function, type, method type, json, text, xml, script, url, and data read address; method: The request method. It supports get, post, data, sent data, contentType, request contentType header, header, Object, and additional request headers.
$. Ajaxf. get (url, data, callback, type)
Get Data
$. Ajaxf. post (url, data, callback, type)
Get data through post
We will not explain the meaning of the letter as soon as you read the name.
$. 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)
  
The following shows how to obtain the HTML code of the Youku homepage.Copy codeThe Code is 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 = "get Data" id = 'fdemo _ get'/>

Unfortunately, the kid doesn't know how to run the code on the page in the garden. Only your friends can test it.
:/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.