JSONP跨域,实现cookies共享

<!DOCTYPE html>

<html>
	<head>
		<meta charset='utf-8'>
		<title>JSONP跨域,实现cookies共享</title>
		<script> 
			function callback(result) {//定义方法
				//设置cookies,或其他操作
				alert(result.Name);
			}
		</script>
		<script src="http://localhost/yygl/html/ajax.php"></script>
		<!-- 
			对应的 ajax.php 代码
			<?php
				// echo 'callback({"Name": "LuoHang","Age" : 1991});';
			?>
	 	-->
	 	<!-- 当页面 执行到 
	 		<script src="http://localhost/yygl/html/ajax.php"></script> 
	 		 这一段时代码时
	 		 相当于 执行 callback({"Name": "LuoHang","Age" : 1991}); 这段js代码
 	 	-->
	</head>
	<body>
	</body>
</html>





动态插入script

		<script>
			var domain = window.location.search;
			domain = domain.replace("?domain=","");
			domain = decodeURIComponent(domain);//传域名
			if(domain){
				var script = document.createElement("script");
				script.type = "text/javascript";
				script.src = domain + "/Mes/SysAdmin/BaseCURD/GetCrossDomainData";
				document.body.appendChild(script);
			}
		</script>

相关文章

文章浏览阅读2.4k次。最近要优化cesium里的热力图效果,浏览...
文章浏览阅读1.2w次,点赞3次,收藏19次。在 Python中读取 j...
文章浏览阅读1.4k次。首字母缩略词 API 代表应用程序编程接口...
文章浏览阅读802次,点赞10次,收藏10次。解决一个JSON反序列...
文章浏览阅读882次。Unity Json和Xml的序列化和反序列化_uni...