开发者

Avoid x-domain solutions

I'm currently working on a web application that customers can add to their webpages by adding a javascript link to a js file on my server. The application read all the javascriptfiles from my se开发者_开发问答ver, but I still get an error when trying to use ajax to get data from my database. I didn't think that would be a problem because the files is on my server.

Can I fix this or do I have to make a cross-browser solution? I don't have any control over the costumers server.

Thanks in advance

Mikael


This is not possible: When you execute a remote script, it runs in the context of the containing document.

There are some popular workarounds for this:

  • Using an iframe, which fixes the cross-domain problem but doesn't integrate well with the remote site (e.g. no custom styling)

  • Using JSONP to make cross-domain Ajax requests (detailed explanation here)

  • Using a server-side proxy script (not an option in this scenario)

  • Using YQL (I'm not familiar with this but it's said to work)


The same origin policy is based on the host document not the script itself.

You need to use a cross domain ajax technique.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜