JSONP跨域,实现cookies共享

来源:互联网 发布:shift js按键 编辑:程序博客网 时间:2024/05/19 22:02
<!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>



0 0