开发者

Can't get the contents between <script>?

开发者 https://www.devze.com 2023-03-14 12:14 出处:网络
I have a page http://www.a.com/hellowhich will return a JSON, now I want to get it in http://www.b.com I tried several cross-domain-ajax method, but none of them worked:

I have a page http://www.a.com/hello which will return a JSON, now I want to get it in http://www.b.com I tried several cross-domain-ajax method, but none of them worked:

1. I have no control over a.com(though I trust it, so don't worry about XSS)

2. to access a.com/hello, cookie/session are needed, so I c开发者_C百科an't use a proxy on b.com.

Then I turn my eyes to other method, I notice that img, script, iframe can get contents cross domain, so I try to use them to load the content:

1. iframe: I can see the content in iframe, but I can't get it from js due to same-origin-policy.

2. img: Can't see the content.

3. script: I can see that content is loaded and evaluated, but when I try to get the contents between the <script> using innerHTML, I got nothing.

My question is, how to do the 3rd method above? or is there other ways that could solve my problem?

The content of what http://www.a.com/hello is like:

 {"candidate":[{"id":251574647,"name":"\u5f20\u6f47"}]} 


No, you can not directly the access the contents of a script element in the page. To be able to do what you want you will have to use JSONP or have the output of your script set/update a specific variable.


have a look at http://en.wikipedia.org/wiki/JSONP

0

精彩评论

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