跨域AJAX请求返回HTML(不是jsonp) [英] Cross Domain AJAX request return HTML (not jsonp)

查看:1626
本文介绍了跨域AJAX请求返回HTML(不是jsonp)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此插件: https:// github.com/padolsey/jquery.fn/tree/master/cross-domain-ajax/

这是我的代码:

   $.ajax({
      dataType: 'html',
      type: 'GET',
      url: 'http://www.google.com',
      crossDomain: true
  }).done(function(data) { 
       $("#box").html('').append(data);
  });



从我的理解,即使我有dataType:'html' code>我相当确定这仍然让我在JSONP的反应。

From my understanding, even though I have dataType: 'html' I'm fairly sure this is still getting me a response in JSONP.

我想要能够抓取整个页面的html,所有我需要显示的页面。可比的iframe。我需要通过ajax这样做的原因是因为最终我需要传递参数到我正在使用的URL。什么是以完整HTML返回网页内容的最佳方式,以便我可以显示网页?我需要做任何事情以返回页面脚本/样式表吗?

I want to be able to grab the entire html of the page, everything I need to display the page in full. Comparable to an iframe. The reason I need to do this through ajax is because eventually I am going to need to pass parameters to the URL I am using. What is the best way to return a page's content in full HTML, so that I may display the page? Do I need to do anything to return the pages scripts/stylesheets as well?

基本上,我调用的URL需要返回,以便我可以追加return到div id,然后div的id应该看起来像我正在调用的页面,好像我是在浏览器窗口中独立加载该页面。

Basically, the URL that I am calling needs to be returned so that I can append the return to a div id, and that div id should then look exactly like the page I was calling, as if I were to load that page independently in a browser window.

谢谢

推荐答案

您可以尝试Ajax跨源的jQuery插件。

You can try Ajax-cross-origin a jQuery plugin.

http://www.ajax-cross-origin.com/

    $.ajax({
        crossOrigin: true,
        url: url,
        success: function(data) {
            console.log(data);
        }
    });

这篇关于跨域AJAX请求返回HTML(不是jsonp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆