如何用AJAX提取跨域HTML?

某些站点上有基于AJAX的聊天应用程序,它定期轮询服务器并接收HTML片段。 希望编写一个备用移动前端,使用JS直接查询现有后端(即不将服务器用作反射器)。

这其中有两个问题:

1、服务器所有者不会介意我这样做,但是它不会竭尽全力为我提供帮助,因此与服务器交谈的格式不是我可以更改的。也就是说,服务器不会使用JSON,更不用说JSONP了。HTML片段对我而言,本质上还是文本。

2、我需要具有可手动解析的返回值,而无需解析/插入等。

如果有人对此事有任何建议,我将不胜感激。

could you create a php proxy, ajax send url to fetch to local php(or other serverside script) php uses curl to fetch that page and returns result.

  • 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, e.g. Access-Control-Allow-Origin: example.com).