ajax成功跨域_自己写的

跨域的简单原理:一般浏览器会阻止js请求异端服务器(A服务器请求B服务器)。js连接却除外 如:<script type="text/jscript" src="http://www.yourtour.cc/ajax_test.js"></script> 还有iframe、css、script  都可以进行异端请求数据。

本地html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/jscript" src="jquery-1.11.2.min.js"></script>
<script type="text/jscript" src="http://www.yourtour.cc/ajax_test.js"></script>
</head>

<body>
<div id="con" style="height: 300px;  300px; margin: 0 auto; background: #09F"></div>
<input name="1111" type="button" value="请求ajax" onclick="ajax()"/>
</body>
</html>

需要放服务器上的

js文件

function ajax(){
    $.ajax({
        url:'t.html',
        success: function (html){
            alert(html);    
        }    
    })    
}

需要请求的页面(php,html)

恭喜你,请求到了跨域ajax数据
原文地址:https://www.cnblogs.com/wesky/p/4590986.html