最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - crossdomain.xml configuration - Stack Overflow

programmeradmin4浏览0评论

I have to call to a web service from javascript using ajax:

$.ajax({
    type: "GET",
    url: "http://[REMOTE-SERVER-IP]:8080/api/service",
    contentType: "application/jsonp",   
    crossDomain: true,
    success: successFunc,
    error: errorFunc
});

I read that to grant access to the method, a "crossdomain.xml" must be created in the server http://[REMOTE-SERVER-IP]:8080/crossdomain.xml:

<cross-domain-policy>
   <allow-access-from domain="[SERVICE-CALLER-IP]"/>
</cross-domain-policy>

But after doing that, when I try to call to the method, I'm getting this error from the javascript debugger:

XMLHttpRequest cannot load http://[REMOTE-SERVER-IP]:8080/[URL]. Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin

What am I doing bad?

Thank you very much!!!

I have to call to a web service from javascript using ajax:

$.ajax({
    type: "GET",
    url: "http://[REMOTE-SERVER-IP]:8080/api/service",
    contentType: "application/jsonp",   
    crossDomain: true,
    success: successFunc,
    error: errorFunc
});

I read that to grant access to the method, a "crossdomain.xml" must be created in the server http://[REMOTE-SERVER-IP]:8080/crossdomain.xml:

<cross-domain-policy>
   <allow-access-from domain="[SERVICE-CALLER-IP]"/>
</cross-domain-policy>

But after doing that, when I try to call to the method, I'm getting this error from the javascript debugger:

XMLHttpRequest cannot load http://[REMOTE-SERVER-IP]:8080/[URL]. Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin

What am I doing bad?

Thank you very much!!!

Share Improve this question edited Nov 19, 2012 at 11:27 user1702964 asked Nov 15, 2012 at 9:13 user1702964user1702964 1,1194 gold badges12 silver badges14 bronze badges 1
  • Do you have access to the server that runs the web service? If not, crossdomain.xml won't be any use. You should consider looking at JSON-P or CORS instead. – chrisfrancis27 Commented Nov 15, 2012 at 9:37
Add a ment  | 

1 Answer 1

Reset to default 4

You can prefer two options here and both assumes that you can access the server.

  • The first option is to add callback=? parameter to request url, and modify the server response. Server should add the callback function to the response in the following format

    callback_function_ing_from_url([your_server_response])

  • The second option is to add Access-Control-Allow-Origin: * header to your server response. Or you can specify the address like Access-Control-Allow-Origin: [your_client_address]

I prefer to option 2 since it is the convenient way to acplish your task, and also, you can control your server response, much more secure than the option 1.

You can get additional info from CORS

发布评论

评论列表(0)

  1. 暂无评论