ajax跨域问题之script

   /*
    分析原理:
    通过动态创建script标签来设置其的url属性来动态外部链接
    传递数据可以附加到Url参数上面
    外部链接里生成js的json格式数据
   

   */

<html>
	<head id="head">
	</head>
	<body>
		<script>	
			function getJsData(url){
;
				var Snode = document.createElement("script");
				Snode.setAttribute("type", "text/javascript");
				Snode.setAttribute("language", "javascript");
				Snode.setAttribute("src", url);
				document.body.appendChild(Snode);
				//ie  onreadystatechange 
			
				Snode.onreadystatechange=function(){
						alert(param.name+'\n'+param.php);
					}
				// FF 
				Snode.onload=function(){
					alert(param.name+'\n'+param.php);
				}
			
			}
		
			
		
		</script>
		<!-- 这是本地配置的地址 -->
		<button onclick="getJsData('http://webv9.com/test.php');">query</button>
	</body>
</html>

 test.php

<?php
	$arr=array('name'=>'wangxiaopi','php'=>'lampborthor');
	echo 'var param='.json_encode($arr);
?>

  

posted on 2012-01-11 19:51  长的比较肥  阅读(198)  评论(0)    收藏  举报