Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 加载ajax时javascript代码停止工作_Php_Javascript_Html_Ajax - Fatal编程技术网

Php 加载ajax时javascript代码停止工作

Php 加载ajax时javascript代码停止工作,php,javascript,html,ajax,Php,Javascript,Html,Ajax,代码1:当我点击clickhere时,它应该隐藏id=adiv的div,当我再次点击时,它会再次显示 代码2和3:ajax代码代码2属于代码3。这段代码每1秒刷新一次php页面。我把代码1放在用ajax打开的php页面中 为什么在页面中加载ajax代码代码2和代码3后,“代码1”停止工作?当我点击点击这里,它什么也不做 但是在加载ajax之前,代码1运行良好 代码2和代码3运行良好,我对它们没有问题。唯一的问题是代码1 当我调试此页面时,代码1中的行:hideshowdocument.getEl

代码1:当我点击clickhere时,它应该隐藏id=adiv的div,当我再次点击时,它会再次显示

代码2和3:ajax代码代码2属于代码3。这段代码每1秒刷新一次php页面。我把代码1放在用ajax打开的php页面中

为什么在页面中加载ajax代码代码2和代码3后,“代码1”停止工作?当我点击点击这里,它什么也不做

但是在加载ajax之前,代码1运行良好

代码2和代码3运行良好,我对它们没有问题。唯一的问题是代码1

当我调试此页面时,代码1中的行:hideshowdocument.getElementById'adiv'显示给我,此eror:Uncaught ReferenceError:hideshow不是定义的匿名函数

但是我真的不明白为什么我会有这个问题?我需要做什么来解决这个问题

编辑:这里有人说,因为代码1在我用ajax打开的页面中,所以代码会从客户机的dom中删除。有什么解决办法吗

1脚本:

<a href="javascript:hideshow(document.getElementById('adiv'))">Click here</a>

<script type="text/javascript">
function hideshow(which){
if (!document.getElementById) { return; }
if (which.style.display=="block") { which.style.display="none"; }
else { which.style.display="block"; }
}
</script>

<div id="adiv" style="font:24px bold; display: block">Now you see me</div>
2.ajax代码:

<script type="text/javascript">
function refresh(name, url, info, info_1, info_2, type)
{
    if (type == "send") {
        document.getElementById("send_"+name).innerHTML = info;  // just show the txt that send
        Input(name);
        if (info == "") {
            document.getElementById(name).innerHTML="";
            return;
        } 
    }
    if (window.XMLHttpRequest) {    // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else {  // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    var xhr = new XMLHttpRequest();
    var params = "c=<?php echo $_GET["c"]; ?>&info="+info+"&info_1="+info_1+"&info_2="+info_2;
    xhr.open("POST",url,true);
    xhr.onreadystatechange = function() {
        if( this.readyState == 4 && this.status == 200) {
            document.getElementById(name).innerHTML = this.responseText;
        }
    };
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.setRequestHeader("Content-length", params.length);
    xhr.setRequestHeader("Connection", "close");
    xhr.send(params);
    return false;
}
</script>
<script type="text/javascript">
           setInterval("refresh('aaa', 'refresh.php', '', '', '', 'refresh')", "1000");
           </script>
3播放ajax代码的代码:

<script type="text/javascript">
function refresh(name, url, info, info_1, info_2, type)
{
    if (type == "send") {
        document.getElementById("send_"+name).innerHTML = info;  // just show the txt that send
        Input(name);
        if (info == "") {
            document.getElementById(name).innerHTML="";
            return;
        } 
    }
    if (window.XMLHttpRequest) {    // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else {  // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    var xhr = new XMLHttpRequest();
    var params = "c=<?php echo $_GET["c"]; ?>&info="+info+"&info_1="+info_1+"&info_2="+info_2;
    xhr.open("POST",url,true);
    xhr.onreadystatechange = function() {
        if( this.readyState == 4 && this.status == 200) {
            document.getElementById(name).innerHTML = this.responseText;
        }
    };
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.setRequestHeader("Content-length", params.length);
    xhr.setRequestHeader("Connection", "close");
    xhr.send(params);
    return false;
}
</script>
<script type="text/javascript">
           setInterval("refresh('aaa', 'refresh.php', '', '', '', 'refresh')", "1000");
           </script>

javascript是否位于div或ajax代码覆盖的其他元素中?如果是这样,则该代码将从客户端的dom中删除。@developerwk是的,代码1在我用ajax打开的页面中。有什么解决办法吗?