简体   繁体   中英

AJAX Fetch Cross-Domain HTML

I fear I may be trying to do something that certain security policies are specifically designed to forbid.

So there's a certain site with a certain AJAX-based chat application. It periodically polls the server and receives HTML fragments in return. I am looking to write an alternate mobile frontend that directly queries the existing backend using JS (ie does not use my server as a reflector).

Two main issues here that make this different from most such questions:

  1. The server owner wouldn't mind me doing this but he's not going to go out of his way to help me, and so the format for talking with the server is not something I can change. That is, the server doesn't talk JSON let alone JSONP. It's HTML fragments but for my purposes that's essentially text.

  2. I need to have the return value available to parse manually. It should not be automatically parsed/inserted/what-have-you through inclusion in the DOM or some other such mechanism.

If anyone has some advice on this matter, I would really appreciate it.

  • You could use a server side script to proxy it through your server.
  • You could use YQL as the middle man and use JSONP or CORS.
  • Tell the person on the other server to set up CORS for your server (tell them to add a header for each request, eg Access-Control-Allow-Origin: example.com ).

你能创建一个php代理,ajax发送url来获取本地php(或其他服务器端脚本)php使用curl来获取该页面并返回结果。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM