Javascript jquery Ajax cross-origin access to post data

Source: Internet
Author: User

If it's just get, there will be more solutions, such as jsonp.

 

Post is a little troublesome. I searched the internet and found a lot of solutions. I feel that this method of using flash for proxy is quite good, and the browser compatibility is also very good, however, the premise is that the Web server is managed by yourself. Because of flash-based security rules, you need to put a crossdomain in the root directory of the website. XML, all of which are allowed here:

 

<? XML version = "1.0"?> <Br/> <! Doctype cross-domain-Policy System "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> <br/> <! -- Policy file for xmlsocket: // socks.mysite.com --> <br/> <cross-domain-Policy> <br/> <site-control permitted-Cross-Domain-policies = "Master-only"/> <br/> <allow-access-from domain = "*"/> <br/> <allow-http-request-headers-from domain = "*" headers = "*" /> <br/> </Cross-Domain-Policy>

 

I have seen some developers in China package their own, but there are still some gaps in this comparison. We suggest using this. He has made Plug-ins for prototype, dojo, and jquery, which is really convenient:

 

Http://flxhr.flensed.com/

 

 

Take jquery as an example:

 

1. First download flxhr and the corresponding jquery plug-in:

A> http://flxhr.flensed.com/code/releases/jquery/jquery.flXHRproxy.js

B> http://plugins.jquery.com/project/XHR

Http://flxhr.flensed.com/download.php

 

 

2. embedded scripts on the page:

<SCRIPT type = "text/JavaScript" src = "xxx/flxhr. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "xxx/1.4.2/jquery. Min. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "xxx/jquery. xhr. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "xxx/jquery. flxhrproxy. js"> </SCRIPT>

3. Example Code :VaR usecount = 0; jquery (document ). ready (function () {jquery. flxhrproxy. registeroptions ("http://test.getify.com/flXHR-tests/", {xmlresponsetext: false, loadpolicyurl: "http://test.getify.com/flXHR-tests/policy.php"}) ;}); function doit () {var COUNT = (usecount + 1 ); for (VAR I = 0; I <count; I ++) {var requestbody = "My name is jquery-test (#" + (++ usecount) + ")"; jquery. ajaxsetup ({transport: 'flxhrproxy', error: handleerror}); jquery. post ("http://test.getify.com/flXHR-tests/textme.php", requestbody, handleloading, "text/plain") ;}} function handleloading (data, status, xhrobj) {If (xhrobj. readystate = 4) {alert ("readystate:" + xhrobj. readystate + "/nresponsetext:" + xhrobj. responsetext + "/nstatus:" + xhrobj. status + "/nstatustext:" + xhrobj. statustext + "/nsource Object ID:" + xhrobj. instanceid) ;}} function handleerror (xhrobj, errtype, errobj) {alert ("error:" + errobj. number + "/ntype:" + errobj. name + "/ndescription:" + errobj. description + "/nsource Object ID:" + errobj. srcelement. instanceid );}

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.