xmlhttp.responseText返回脚本标记的内容


xmlhttp.responseText returns contents of the script tag

    <script>
function refresh_event(){//CALLED WHEN EVENT IS CHANGED
    document.getElementById("frm_event").submit();
}
function click1(i,stuid){//AJAX CODE
    var obj = document.getElementById("event");
    var eid = obj.options[obj.selectedIndex].value;
    var xmlhttp;
    var j=document.getElementById("link"+i).innerHTML;
    if(window.XMLHttpRequest){
        xmlhttp = new XMLHttpRequest();
    }
    else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            //alert("in");
            document.getElementById("link"+i).innerHTML=xmlhttp.responseText;
        //  alert(xmlhttp.responseText);
        }
    }
    //alert("a"+j+"b");
    xmlhttp.open("GET","register.php?i="+j+"&sid="+stuid+"&eid="+eid+"&val=1&t="+Math.random(),true);
    xmlhttp.send();
}
</script>
<?php 
if($val==0){//LANDING PAGE
?>
<?php
    if(mysqli_connect_errno()){
        echo "connection error";
    }
    $query="select name,eid from event_info";
    $result = mysqli_query($con,$query);
?>
<!-- CODE TO POPULATE EVENT LIST -->
<form id="frm_event" method="GET" action="register.php">
    Events:<select id="event" name="event" onchange="refresh_event()">
    <?php
        if($event==0){
    ?>
    <option value=0 selected> --select-- </option> <!-- IF NOTHING IS SELECTED -->
    <?php
        }else{
    ?>
    <option value=0> --select-- </option>   <!-- IF EVENT IS SELECTED -->
    <?php
        }
    ?>
    <?php
        while($row=mysqli_fetch_array($result)){ //FETCH EVENT FROM DATABASE
            if($event==$row['eid']){
    ?>
    <option value=<?=$row['eid'] ?> selected> <?=$row['name'] ?> </option>
    <?php
            }
            else{
    ?>
    <option value=<?=$row['eid'] ?>> <?=$row['name'] ?> </option>
    <?php
            }
        }
    ?>
    </select>
</form>
<?php
    $query="select stuid,name from stud_info";
    $result = mysqli_query($con,$query);
    $i=1;
?>
<br>
<table>
    <?php
        if($event==0){//IF EVENT IS NOT SET
    ?>
    <?php
            while($row=mysqli_fetch_array($result)){
    ?>
    <tr>
        <td> 
            <p><?=$row['name'] ?></p>
        </td>
        <td>
            <a href="javascript:click1(<?=$i ?>,<?=$row['stuid'] ?>);" name="link<?=$i ?>" id="link<?=$i ?>">Assign</a>
            <!--<a href="javascript:void(0);"  id="link<?=$i ?>" onclick="click()"> Assign 1</a>-->
        </td>
    </tr>
    <?php
                $i++;
            }
        }
        else{//IF EVENT IS SET
    ?>
    <?php
            while($row=mysqli_fetch_array($result)){//FETCH REGISTERED STUDENT FROM DATABASE
                $regid=0;
                $stuid=$row['stuid'];
                $query_event="select regid from event_register where stuid='$stuid' and eid='$event'";
                $result_event=mysqli_query($con,$query_event);
                $count1 = mysqli_num_rows($result_event);
    ?>
    <tr>
        <td> 
            <p><?=$row['name'] ?></p>
        </td>
        <td>
            <?php
                if($count1>0){//IF STUDENT IS REGISTERED FOR THIS EVENT
            ?>
                <a href="javascript:click1(<?=$i ?>,<?=$row['stuid'] ?>);" name="link<?=$i ?>" id="link<?=$i ?> name=">Remove</a>
            <?php
                }
                else{
            ?>
                <a href="javascript:click1(<?=$i ?>,<?=$row['stuid'] ?>);" name="link<?=$i ?>" id="link<?=$i ?>">Assign</a>
        </td>
    </tr>
    <?php
                }
                $i++;
            }
        }
    ?>
</table>
<?php
}
else{
    //$_GET['change']="new";
    $val=0;//RESET THE VALUE
    $var =$_GET['i'];
    $sid = $_GET['sid'];
    $eid = $_GET['eid'];
    if($var=="Assign"){
    //INSERT QUERY
        $query="insert into event_register (stuid,eid) values ('$sid','$eid')";
        $result = mysqli_query($con,$query);
        echo "Remove";
    }
    else{
    //delete
        $query="delete from event_register where stuid='$sid' and eid='$eid'";
        $result = mysqli_query($con,$query);
        //if(mysqli_affected_rows($con)>0){
            echo "Assign";
        //}
        /* else{
            echo "Assign";
        } */
    //return "return";
    }
}
?>

是我的代码。使用PHP和javascript。尝试使用ajax从数据库获取值。但是xmlhttp返回的值。responseText出现问题

上面的

是脚本标记的部分内容。xmlhttp。responseText返回脚本标签的全部内容,包括标签本身。

尝试将getElementbyId更改为getElementsbyName仍然没有成功。

执行ajax调用的代码段位于末尾。

我不知道为什么对你但它发生在我身上发生,原因如下:我叫js和php文件相同的名称,例"脚本",然后在我的js文件,说"script.js",而不是设置处理程序url script.js script.php我设置它,所以,我可能有script.php回声"分别地在我的php脚本,而不是整个文本的js文件宣读。