跨域$ .ajax请求不起作用 [英] Cross-domain $.ajax request is not working

查看:191
本文介绍了跨域$ .ajax请求不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面包含的是我试图用来显示另一个页面的HTML内容的代码.我无法使代码正常工作,并且每次都收到错误.我在这里想念什么?

Included below is the code that I am trying to use to display the HTML contents of another page. I am unable to get the code to work and am receiving an error each time. What am I missing here?

$.ajax({
    url: 'http://www.msn.com',  
    type: 'GET',
    dataType : "text/html",
    success: function (result) {
        alert('success');
        alert(result);
    },
    error: function() { 
       alert('error');
}
});

推荐答案

您不能进行跨域AJAX请求(除非专门为其设置了服务器).

You cannot do a cross-domain AJAX request (unless the servers are specifically set up for it).

最好的办法是在服务器上调用PHP脚本,然后从另一台服务器获取HTML并将其发送回您的页面.

The best you can do is call a PHP script on your server, which in turn gets the HTML from the other server and sends it back to your page.

这篇关于跨域$ .ajax请求不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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