Ming
Ming

Reputation: 1693

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 (i.e. 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.

Upvotes: 0

Views: 1207

Answers (2)

alex
alex

Reputation: 490607

  • 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).

Upvotes: 2

Last Rose Studios
Last Rose Studios

Reputation: 2481

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.

Upvotes: 0

Related Questions