<!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>