简体   繁体   English

如何使用jQuery ajax在不同的主机上检索和显示html / asp / aspx页面?

[英]How do I retrieve and display html/asp/aspx page on different host using jQuery ajax?

I have an html page, which is a dynamically created asp/aspx page on http://host2.mydomain.com . 我有一个html页面,它是http://host2.mydomain.com上动态创建的asp / aspx页面。 I have no control over the html page. 我无法控制html页面。 I cannot modify it in any such way. 我无法以任何这种方式修改它。 I cannot modify this page; 我无法修改此页面; so, setting document.domain is out of the question, unfortunately. 因此,不幸的是,设置document.domain是不可能的。 This html page is compiled by a 3rd-party vendor and the code is close-source; 这个html页面是由第三方供应商编译的,代码是封闭源代码; I cannot view it or change it. 我无法查看或更改它。 I want to retrieve and display this page on http://host1.mydomain.com/page1.jsp using Ajax. 我想使用Ajax在http://host1.mydomain.com/page1.jsp上检索并显示此页面。

FYI: host1 is being served by IIS 7 and Apache Tomcat (for JSP pages). 仅供参考:IIS 7和Apache Tomcat(用于JSP页面)正在为host1提供服务。 And host2 is using IIS 7 and ASP. host2使用IIS 7和ASP。

How can I retrieve this page using a Ajax POST request? 如何使用Ajax POST请求检索此页面?

Thank you. 谢谢。

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 由于跨域策略,您无法使用标准的AJAX调用,因此必须使用JSONP或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. 同样,一个常见的“陷阱”是跨域策略也会阻止安全到不安全的ajax。 So a https:// page cannot request a http:// page and vice versa/ 因此, https://页面无法请求http://页面,反之亦然/

By setting proper CORS headers if you are using modern browsers. 如果您使用的是现代浏览器,请设置适当的CORS标头。 Have a look here 在这里看看

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 您只是跨子域,所以可以使用iframe来完成此任务,请查看此问题- 有关跨域(子域)ajax请求的问题

The solution referenced: http://www.tomhoppe.com/index.php/2008/03/cross-sub-domain-javascript-ajax-iframe-etc/ 参考的解决方案: http : //www.tomhoppe.com/index.php/2008/03/cross-sub-domain-javascript-ajax-iframe-etc/

您编写服务器端脚本以检索页面内容,然后使用Ajax请求您的脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用jQuery Ajax显示aspx页面的响应 - How to display a response from aspx page using jquery ajax 如何使用javascript / jQuery / ajax打印不同的页面? - How do I print different page using javascript/jQuery/ajax? 如何使用 jQuery/AJAX 在 HTML div 内加载 html 页面内容? - How do I load html page content inside of an HTML div using jQuery/AJAX? 如何使用 javascript 在单独的 html 页面上显示答案? - How do I display an answer on a separate html page using javascript? 我在ASP.NET应用程序中使用ajax调用,并且从jquery Ajax调用中获取了整个HTML页面作为响应 - I'm using ajax call in ASP.NET application and I'm getting entire HTML page as response from jquery Ajax call 如何在aspx页面中检索jquery的post请求参数 - how to retrieve post request parameter of jquery in aspx page 如何使用 jQuery 在同一页面上重用 HTML 元素? - How do I reuse an HTML element on the same page using jQuery? 将变量从HTML页检索到.aspx页 - Retrieve variables from a HTML page into a .aspx page 使用jQuery和Ajax的Twitter搜索API-演示未显示结果时,如何检索数据 - Twitter search API using jQuery and Ajax - How do I retrieve the data as my demo shows no results 如何使用js和jquery onclick从另一个HTML页面检索代码 - How can I retrieve code from another html page using js & jquery, onclick
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM