<!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>原文链接:https://www.f2er.com/json/289638.html