在ajax的回调函数中,先获取js脚本的值,赋值到页面的某一个控件,比如一个div,如:
document.getElementById("uccenter").innerHTML=data.ucString; //赋值给id为uccenter的div
然后获取此div中的script对象,如:
var myDivScript = document.getElementById("uccenter").getElementsByTagName("script").item(0);
再创建一个新的script对象,因为只有新的对象页面才会执行
var newScript = document.createElement("script");
把js脚本的属性值赋值给新的script对象
newScript.setAttribute("src",myDivScript.getAttribute("src")); newScript.setAttribute("reload",myDivScript.getAttribute("reload")); newScript.innerHTML = myDivScript.innerHTML;最后,添加心script对象到页面:
document.getElementsByTagName("HEAD").item(0).appendChild(newScript);
// 用户注册完成回调函数001 function loginSuccessAjaxCallback(data){ if(null == data.resultString || "" == data.resultString) { if(null != data.ucString || "" != data.ucString) { document.getElementById("uccenter").innerHTML=data.ucString; var myDivScript = document.getElementById("uccenter").getElementsByTagName("script").item(0); var myDivScript2 = document.getElementById("uccenter").getElementsByTagName("script").item(1); var newScript = document.createElement("script"); var newScript2 = document.createElement("script"); newScript.setAttribute("src",myDivScript.getAttribute("reload")); newScript.innerHTML = myDivScript.innerHTML; newScript2.setAttribute("src",myDivScript2.getAttribute("src")); newScript2.setAttribute("reload",myDivScript2.getAttribute("reload")); newScript2.innerHTML = myDivScript2.innerHTML; document.getElementsByTagName("HEAD").item(0).appendChild(newScript); document.getElementsByTagName("HEAD").item(0).appendChild(newScript2); } window.location.reload(); } else { $('#loginResuleMessage').html(data.resultString); } }
这里的js脚本形如:
<script type="text/javascript" src="http://localhost/bbs/api/uc.PHP?time=1388937248&code=ae28TF01utAnYLk0%2BhVarCC0mO8hxTN7K7JoPAHmkHN3sX1OQBv6IExLuUA66n78X%2B8mSnvdpathuBSOm3ph9NqKHJbn3gMQ5W%2Bmyn%2BbFwYQ8zMaIV5BXhpYzoR0Hx0a6Qa02e0gcNH%2B2ROVk8MF4Ms8CUFeyBMVuBahxbCeaQ" reload="1"></script><script type="text/javascript" src="http://localhost:8080/yxw/api/uc.PHP?time=1388937248&code=1752B0%2FcsBy%2FZkYV0Hf2cxoxk5tx2IK4CwhYqVRbvuzcqL051vFGWmq5E0vaJw7tixqDZb%2BEAtgPPNkgten9owDk%2FXu%2B5YRJ8XBT6tjlHery2BtZPNjlUyZKBtamHs6%2FLEUPTciQqB5vuxjW0%2F1ib%2FTqpZL8CweG%2FPkgFiZ41Q" reload="1"></script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。