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

利用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}