<html>
<head></head>
<body>
<script type="text/javascript">alert(sUrl);
function include1(src,encoding,fun)
{
src="http://127.0.0.1:8088/tixing/result.php"+"?temp=" + Math.random(); ;
alert(src);
//alert("h");
var s = document.createElement('script');
s.type='text/javascript';
s.charset=encoding; //'gb2312';
s.src = src;
var tags =document.getElementsByTagName('head');
if(typeof(fun)=='function'){
if( document.all ){
s.onreadystatechange = function(){
if(/(complete|loaded)/.test(this.readyState)){
fun(); s.onreadystatechange = null; s.parentNode.removeChild(s);
}};
}else{
s.onload = function(){ fun(); s.onload = null; s.parentNode.removeChild(s); };
}
}
tags[0].appendChild(s);
};
function include2(url) {
//alert(url);
//return
url="http://127.0.0.1:8088/tixing/result.php"+"?temp=" + Math.random(); ;
alert(url);
var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status == 200) {
alert(xhr.responseText)
//alert(xhr.requestText); //具体你自己处理吧.获得数据后修改什么的
}
}
};
xhr.open("GET",url,false);
xhr.send(null);
}function setcheck()
{
sUrl="http://127.0.0.1:8088/tixing/result.php"+"?temp=" + Math.random();
_script = document.createElement('script')
_script.setAttribute("type", "text/javascript");
_script.setAttribute("src",sUrl);
_script.setAttribute("charset", "gb2312")
document.getElementsByTagName("head")[0].appendChild(_script) setTimeout("check()",1000);
return;
}
function check()
{
//trace.innerHTML+="<br>"+hqr;
alert(hqr);
document.getElementsByTagName("head")[0].removeChild(_script)
}
//include1("http://127.0.0.1:8088/tixing/result.php","gb2312",function(){alert(hqr);});
</script>
<input type=button value=hch126163的代码 onclick='include1("http://127.0.0.1:8088/tixing/result.php","gb2312",function(){alert(hqr);});'>
<input type=button value=感谢cj205的代码 onclick='include2("http://127.0.0.1:8088/tixing/result.php");'>
<input type=button value=我自己的代码 onclick='setcheck();'>
</body>
</html>
上面效果一样,感谢cj205和hch126163给提供了代码,感谢IBM_hoojo点拨。问题症结就在缓存问题,IE存在FF不存在,这样就都好了,谢谢
<head></head>
<body>
<script type="text/javascript">alert(sUrl);
function include1(src,encoding,fun)
{
src="http://127.0.0.1:8088/tixing/result.php"+"?temp=" + Math.random(); ;
alert(src);
//alert("h");
var s = document.createElement('script');
s.type='text/javascript';
s.charset=encoding; //'gb2312';
s.src = src;
var tags =document.getElementsByTagName('head');
if(typeof(fun)=='function'){
if( document.all ){
s.onreadystatechange = function(){
if(/(complete|loaded)/.test(this.readyState)){
fun(); s.onreadystatechange = null; s.parentNode.removeChild(s);
}};
}else{
s.onload = function(){ fun(); s.onload = null; s.parentNode.removeChild(s); };
}
}
tags[0].appendChild(s);
};
function include2(url) {
//alert(url);
//return
url="http://127.0.0.1:8088/tixing/result.php"+"?temp=" + Math.random(); ;
alert(url);
var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status == 200) {
alert(xhr.responseText)
//alert(xhr.requestText); //具体你自己处理吧.获得数据后修改什么的
}
}
};
xhr.open("GET",url,false);
xhr.send(null);
}function setcheck()
{
sUrl="http://127.0.0.1:8088/tixing/result.php"+"?temp=" + Math.random();
_script = document.createElement('script')
_script.setAttribute("type", "text/javascript");
_script.setAttribute("src",sUrl);
_script.setAttribute("charset", "gb2312")
document.getElementsByTagName("head")[0].appendChild(_script) setTimeout("check()",1000);
return;
}
function check()
{
//trace.innerHTML+="<br>"+hqr;
alert(hqr);
document.getElementsByTagName("head")[0].removeChild(_script)
}
//include1("http://127.0.0.1:8088/tixing/result.php","gb2312",function(){alert(hqr);});
</script>
<input type=button value=hch126163的代码 onclick='include1("http://127.0.0.1:8088/tixing/result.php","gb2312",function(){alert(hqr);});'>
<input type=button value=感谢cj205的代码 onclick='include2("http://127.0.0.1:8088/tixing/result.php");'>
<input type=button value=我自己的代码 onclick='setcheck();'>
</body>
</html>
上面效果一样,感谢cj205和hch126163给提供了代码,感谢IBM_hoojo点拨。问题症结就在缓存问题,IE存在FF不存在,这样就都好了,谢谢
script 标签可用于跨越提交,缺点是服务器的响应必须是一个全局变量,这个全局变量可能会和页面的变量冲突。同域还是用Ajax的好!ajax 回调函数接受响应值,是一个局部变量,不用担心冲突问题