jQuery的阿贾克斯,HTML内容跨域 [英] jQuery ajax, get html cross domain

查看:150
本文介绍了jQuery的阿贾克斯,HTML内容跨域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,我想使用Ajax调用的地方,从另一个网页里面的一些HTML内容。不过我挣扎与跨域问题。

I have a webpage where I am trying to use an ajax call to place some html content from another webpage inside. However I am struggling with the cross domain issues.

$('.trigger').click(function(e) {
    e.preventDefault();
    $.ajax({
        url: 'http://myothersite.com',
        datatype: 'text/html',
        type: 'GET',
        success: function(data) {
            var content = data.responseText;
            console.log(content);
        }
    });
});

会有人能够就如何我会去实现这一目标?

Would anyone be able to advise how I would go about achieving this?

谢谢

推荐答案

不能执行的text / html 的跨域得到任何现代浏览器。

You cannot do a cross domain get of text/html in any modern browser.

这是我知道的唯一的返回类型的作品目前正在 JSONP

The only return type that I know of that works currently is jsonp

或者你可以做一些跨域资源共享

这篇关于jQuery的阿贾克斯,HTML内容跨域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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