Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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
Javascript 未捕获引用错误:未定义xmlhttp? 列表 函数showUser(str){ 如果(str==“”){ document.getElementById(“txtHint”).innerHTML=“”; 返回; }否则{ if(window.XMLHttpRequest){ //IE7+、Firefox、Chrome、Opera、Safari的代码 }否则{ //IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数(){ if(this.readyState==4&&this.status==200){ document.getElementById(“txtHint”).innerHTML=this.responseText; } }; open(“GET”、“getuser.php?q=“+str,true”); xmlhttp.send(); } } 桌子{ 宽度:100%; 边界塌陷:塌陷; } 表,td,th{ 边框:1px纯黑; 填充物:5px; } th{文本对齐:左; } 选择一个人: 彼得·格里芬 路易斯·格里芬 约瑟夫·斯旺森 格伦泥潭 PHP脚本的结果应该出现在这里_Javascript_Php_Jquery_Html_Xmlhttprequest - Fatal编程技术网

Javascript 未捕获引用错误:未定义xmlhttp? 列表 函数showUser(str){ 如果(str==“”){ document.getElementById(“txtHint”).innerHTML=“”; 返回; }否则{ if(window.XMLHttpRequest){ //IE7+、Firefox、Chrome、Opera、Safari的代码 }否则{ //IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数(){ if(this.readyState==4&&this.status==200){ document.getElementById(“txtHint”).innerHTML=this.responseText; } }; open(“GET”、“getuser.php?q=“+str,true”); xmlhttp.send(); } } 桌子{ 宽度:100%; 边界塌陷:塌陷; } 表,td,th{ 边框:1px纯黑; 填充物:5px; } th{文本对齐:左; } 选择一个人: 彼得·格里芬 路易斯·格里芬 约瑟夫·斯旺森 格伦泥潭 PHP脚本的结果应该出现在这里

Javascript 未捕获引用错误:未定义xmlhttp? 列表 函数showUser(str){ 如果(str==“”){ document.getElementById(“txtHint”).innerHTML=“”; 返回; }否则{ if(window.XMLHttpRequest){ //IE7+、Firefox、Chrome、Opera、Safari的代码 }否则{ //IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数(){ if(this.readyState==4&&this.status==200){ document.getElementById(“txtHint”).innerHTML=this.responseText; } }; open(“GET”、“getuser.php?q=“+str,true”); xmlhttp.send(); } } 桌子{ 宽度:100%; 边界塌陷:塌陷; } 表,td,th{ 边框:1px纯黑; 填充物:5px; } th{文本对齐:左; } 选择一个人: 彼得·格里芬 路易斯·格里芬 约瑟夫·斯旺森 格伦泥潭 PHP脚本的结果应该出现在这里,javascript,php,jquery,html,xmlhttprequest,Javascript,Php,Jquery,Html,Xmlhttprequest,当我通过Netbeans在Google Chrome浏览器中运行以下HTML页面时,当我试图从列表中选择一个人时,我遇到了这个错误(请参见标题) xmlhttp.onreadystatechange=函数() 这一行代码和下面这一行代码似乎是基于Chrome开发工具的关注领域 选择name=“users”onchange=“showUser(this.value) 有人能指出需要更改的内容吗?就在下面: <html> <head> <title>Lis

当我通过Netbeans在Google Chrome浏览器中运行以下HTML页面时,当我试图从列表中选择一个人时,我遇到了这个错误(请参见标题)

xmlhttp.onreadystatechange=函数()

这一行代码和下面这一行代码似乎是基于Chrome开发工具的关注领域

选择name=“users”onchange=“showUser(this.value)

有人能指出需要更改的内容吗?

就在下面:

<html>
<head>
    <title>List</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Javascript code -->
<script>
         function showUser(str) {
         if (str == " ") {
         document.getElementById("txtHint").innerHTML = " ";
         return;
         } else {
         if (window.XMLHttpRequest) {
         // code for IE7+, Firefox, Chrome, Opera, Safari
         } else {
         // code for IE6, IE5
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
         }
         xmlhttp.onreadystatechange = function() {
         if (this.readyState == 4 && this.status == 200) {
         document.getElementById("txtHint").innerHTML = this.responseText;
         }
         };
         xmlhttp.open("GET","getuser.php?q="+str,true);
         xmlhttp.send();
         }
        }
</script>
        <!-- CSS for HTML table -->
<style>
    table {
    width: 100%;
    border-collapse: collapse;
    }

    table, td, th {
    border: 1px solid black;
    padding: 5px;
    }

    th {text-align: left;
    }
</style>

</head>
<body>

    <form>
        <select name="users" onchange="showUser(this.value)">
            <option value=" ">Select a person:</option>
            <option value="1">Peter Griffin</option>
            <option value="2">Lois Griffin</option>
            <option value="3">Joseph Swanson</option>
            <option value="4">Glenn Quagmire</option>
       </select>   
   </form>
    <div id="txtHint">Result from PHP script should appear here</div>
 </body>
 </html>
加:

xmlhttp=新的XmlHttpRequest()

这样,您就可以使用定义了XMLHttpRequest的javascript引擎满足web浏览器的要求

此外,在正确执行“xmlhttp.onreadystatechange=function()”之前,xmlhttp需要有一个有效的值(句柄)


如果您的浏览器(特别是非常旧的IE浏览器)仍然挑剔,那么请将“xmlhttp”更改为“var xmlhttp”,因为变量名之前的var意味着定义一个新变量。

谢谢。我相信您是正确的。但是关于(句柄)点,你这到底是什么意思?我对这一点比较陌生,如果我不清楚的话,很抱歉。我忘了在上面的评论中标记你。句柄是一个老式的术语,意思是资源。你知道当你做x=y时,你将变量x设置为y的值。但是如果y是比普通数字更特殊的东西那么它的值就是我想称之为句柄的东西,但实际上它是一个对象。谢谢。我明白你的意思。很抱歉问一下,但是你建议我在代码中添加什么来解决函数的问题?比如我应该在代码中添加什么对象,在哪里?任何帮助都将不胜感激。
// code for IE7+, Firefox, Chrome, Opera, Safari