日期:2014-05-16  浏览次数:20699 次

利用JQuery实现Ajax跨域请求(zz)
利用JQuery实现更简单的Ajax跨域请求
<html>
<head>
<title>JQuery学习</title>
<script src="jquery-1.2.6.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    var oBtnTest = $("#btnTest");
    oBtnTest.click(function(){
        oBtnTest.disabled = true;    
        var oResult = $("#result");
        oResult.html("loading").css("color","red");
        jQuery.getScript("http://app.cntvs.com/test/js.txt", 
        function(){            
            oResult.html("name:" + jimmy.name + "<br/>email:" + jimmy.email).css("color","black");            
            oBtnTest.disabled = false;            
        });         
    });    
});    
</script>
</head>
<body>
<button id="btnTest">BtnTest</button>
<div id="result"></div>
</body>
</html>

远程服务器端js.txt的内容为:
var jimmy = {name:"jimmy.yang",email:jimmy.yang@163.com}
1 楼 ydc919 2010-11-30