JS跨域访问 控制

问题场景, 用js访问其他web资源,会出现跨域访问安全限制错误。

 

方案一:

参见文章: https://developer.mozilla.org/en/http_access_control

The summary is that

send extra header like

  1. Origin: http://foo.example  
  2. Access-Control-Request-Method: POST  

Origin is needed

Access-Control-Request-Method is needed only when POST is used

Access-Control-Request-Headers: X-PINGOTHER is needed when having special header (like X-PINGOTHER)

 

server can response with

Access-Control-Allow-Origin: *

that allow the response accepted by pages from other site

 

方案二:

让本地应用程序提供一个接口去做这个链接请求, 即通过后台程序完成。

 

方案三:flash 脚本

url_.text = "http://www.google.com/ig/api?hl=en-US&weather=,,,39904214,116407413";

send_BT.addEventListener(MouseEvent.CLICK,send_);

function send_(evt:Event){

var ld:URLLoader = new URLLoader();

ld.load(new URLRequest(url_.text));

ld.addEventListener(Event.COMPLETE, urlLoader_complete);

}

function urlLoader_complete(evt:Event){

log_.text = evt.target.data;

}

 

你可能感兴趣的:(跨域访问)