作者co3co3 (呵呵)
看板Web_Design
标题[问题] cross domain的div内容取得
时间Mon Aug 10 22:00:22 2015
小弟是网页初学者
最近碰到一个问题迟迟无法解决 所以上来寻求明灯 m(_ _)m
假设我现在有开了两个web service
一个网页是在
http://1.1.1.1:8000/test1.html
另一个网页是在
http://1.1.1.1:9000/test2.html
假设我想要在test1.html抓取test2.html中某个div内容 然後把他秀出来
那我应该要怎麽做呢
如果两个网页都在同一个domain之下的话 我可以透过javascript的load方式
$('
#target-div').load('
http://www.mysite.com/test.php#portfolio-sports');
但是在两个网页分处於不同domain下的情况(一个在port 8000 一个在9000)
有没有什麽比较好的方式 能够让我跨domain去抓某个网页中的div内容呢
网路上有看到一些类似架proxy的方式 但我不想透过proxy
有没有只用单纯的function或是import library可以做到呢?
请教各位了~~
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.231.245.217
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Web_Design/M.1439215226.A.A17.html
1F:推 oToToT: 只能自己弄proxy吧 08/10 22:52
3F:推 oToToT: 楼上那就是在做类似proxy的事啊www 08/11 22:13
4F:→ johnsonct: XDD 嘛 那大概只能交给後端去弄 (? 08/11 23:11
5F:→ johnsonct: blog.caesarchi.com/2011/08/xmlhttprequestajax.html 08/11 23:16
6F:→ johnsonct: 朋友说还有这个方法 不过会有安全性问题 因为所有人都 08/11 23:16
7F:→ johnsonct: 变成可以get这个网域的东西 08/11 23:17
8F:推 storyn26383: 我是用 php 跑 curl 08/11 23:30
9F:→ storyn26383: php 用 curl 抓 test2 的资料,再用 test1 抓 php 08/11 23:31
10F:→ storyn26383: 的资料 08/11 23:31
11F:→ storyn26383: 当然 php 要跟 test1 同 server 08/11 23:32
12F:→ alog: 让机器allow来自你特定domain name下的请求 08/12 02:10
13F:→ alog: --> HTTP access control (CORS) 08/12 02:11
14F:→ alog: 如果机器都不是你的,你乖乖用proxy的概念来做 08/12 02:15