加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

JSONP跨域,实现cookies共享

发布时间:2020-12-16 19:04:32 所属栏目:百科 来源:网络整理
导读:!DOCTYPE htmlhtmlheadmeta charset='utf-8'titleJSONP跨域,实现cookies共享/titlescript function callback(result) {//定义方法//设置cookies,或其他操作alert(result.Name);}/scriptscript src="http://localhost/yygl/html/ajax.php"/script!-- 对应的 a
<!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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读