0

I have an html page, which is a dynamically created asp/aspx page on http://host2.mydomain.com. I have no control over the html page. I cannot modify it in any such way. I cannot modify this page; so, setting document.domain is out of the question, unfortunately. This html page is compiled by a 3rd-party vendor and the code is close-source; I cannot view it or change it. I want to retrieve and display this page on http://host1.mydomain.com/page1.jsp using Ajax.

FYI: host1 is being served by IIS 7 and Apache Tomcat (for JSP pages). And host2 is using IIS 7 and ASP.

How can I retrieve this page using a Ajax POST request?

Thank you.

user717236
  • 4,959
  • 19
  • 66
  • 102

5 Answers5

1

You can't with a standard AJAX call due to cross-domain policies, you would have to use JSONP or a form of JSONP http://en.wikipedia.org/wiki/JSONP

Also, a common "gotcha" is that the cross-domain policies prevent secure to non-secure ajax as well. So a https:// page cannot request a http:// page and vice versa/

nathanjosiah
  • 4,441
  • 4
  • 35
  • 47
  • Thank you very much for your help. Unfortunately, JSONP is not an option for me since I cannot edit the html page from the ASP side. (complicating matters is one host is JSP and the other is ASP). – user717236 Apr 03 '12 at 17:53
1

YQL http://developer.yahoo.com/yql/
and
JSON-Phttp://en.wikipedia.org/wiki/JSONP

Rizwan Mumtaz
  • 3,875
  • 2
  • 30
  • 31
  • Thank you for your suggestion. Will these methods work, even though I have no control over the html page on host2.mydomain.com and it was not designed to encode/decode JSONP? – user717236 Apr 03 '12 at 17:27
  • 1
    use `YQL`. It return complete html of the requested page – Rizwan Mumtaz Apr 03 '12 at 17:30
  • Thank you. What about JSONP? I thought JSONP is only useful if the page being requested is aware that it must encode JSONP. Is that correct? – user717236 Apr 03 '12 at 17:36
  • 1
    `JSON` or `JSON-P` is used when server return data in `JSON` format. `JSON-P` is used to ByPass the same origin policy. – Rizwan Mumtaz Apr 03 '12 at 17:47
1

By setting proper CORS headers if you are using modern browsers. Have a look here

Amareswar
  • 2,048
  • 1
  • 20
  • 36
1

You are just going across subdomains so can do it using an iframe, look to this question - A question about cross-domain (subdomain) ajax request

The solution referenced: http://www.tomhoppe.com/index.php/2008/03/cross-sub-domain-javascript-ajax-iframe-etc/

Community
  • 1
  • 1
Jeff Steil
  • 1,770
  • 17
  • 20
  • Thank you for your help. This would be a great solution if I could modify both pages; however, as I said in the question, I don't have access to the html page. – user717236 Apr 03 '12 at 17:25
  • 1
    Could you just not use ajax and rather include the first page as an iframe on the second page? – Jeff Steil Apr 03 '12 at 17:27
  • I could but the issue I'm having with that is out of the scope of the question I posed. Thank you for your suggestion, though. – user717236 Apr 03 '12 at 18:22
1

you write a server-side script to retrieve the page contents, then you use Ajax to request your script

ilyes kooli
  • 11,959
  • 14
  • 50
  • 79
  • Thank you very much for your suggestion. How can this be done, though? One box is IIS/Tomcat and the other is IIS/ASP. How can I write a Java/JSP script which will talk to the IIS/ASP box and retrieve it's dynamically created html page. I would need at least need some sort of web service which hands off requests from each box. – user717236 Apr 03 '12 at 18:35
  • 1
    Hi, sorry I'm afraid I can't help you! I am a PHP developer, I have not clue how to do it otherwise – ilyes kooli Apr 03 '12 at 21:38
  • Yeah, PHP is my forte, as well. I prefer it. Thank you though for your help. – user717236 Apr 05 '12 at 18:33