Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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 未获取ajax xmlhttp.open中的字符串值(“GET”和“xxx.php?q=”和“x2B”str,true);_Javascript_Php_Mysql_Ajax - Fatal编程技术网

Javascript 未获取ajax xmlhttp.open中的字符串值(“GET”和“xxx.php?q=”和“x2B”str,true);

Javascript 未获取ajax xmlhttp.open中的字符串值(“GET”和“xxx.php?q=”和“x2B”str,true);,javascript,php,mysql,ajax,Javascript,Php,Mysql,Ajax,从下面的示例中,如果值为数字,则其工作正常。但如果值为字符串,则该值显示为0 HTML: <select name="users" onchange="showUser(this.value)"> <option value="">Select a person:</option> <option value="abc-01">Peter Griffin</option> <option value="aaac-02

从下面的示例中,如果值为数字,则其工作正常。但如果值为字符串,则该值显示为0

HTML:

<select name="users" onchange="showUser(this.value)">
  <option value="">Select a person:</option>
  <option value="abc-01">Peter Griffin</option>
  <option value="aaac-02">Lois Griffin</option>
  </select>
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","ajax2.php?q="+str,true);
        xmlhttp.send();
    }
}
$q = intval($_GET['q']);        
echo    $q ;
PHP:

<select name="users" onchange="showUser(this.value)">
  <option value="">Select a person:</option>
  <option value="abc-01">Peter Griffin</option>
  <option value="aaac-02">Lois Griffin</option>
  </select>
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","ajax2.php?q="+str,true);
        xmlhttp.send();
    }
}
$q = intval($_GET['q']);        
echo    $q ;

我得到0作为值。需要帮助吗?

您正在尝试在php中将字符串转换为int,因为htm代码中有字符串值,并且您正在尝试在php代码中将这些值转换为int,因此请相应地更正代码

如果html是

<select name="users" onchange="showUser(this.value)">
  <option value="">Select a person:</option>
  <option value="abc-01">Peter Griffin</option>
  <option value="aaac-02">Lois Griffin</option>
  </select>

您正在尝试在php中将字符串转换为int,因为htm代码中有字符串值,并且您正在尝试在php代码中将这些值转换为int,因此请相应地更正代码

如果html是

<select name="users" onchange="showUser(this.value)">
  <option value="">Select a person:</option>
  <option value="abc-01">Peter Griffin</option>
  <option value="aaac-02">Lois Griffin</option>
  </select>

您正在尝试在php中将字符串转换为int,因为htm代码中有字符串值,并且您正在尝试在php代码中将这些值转换为int,因此请相应地更正代码

如果html是

<select name="users" onchange="showUser(this.value)">
  <option value="">Select a person:</option>
  <option value="abc-01">Peter Griffin</option>
  <option value="aaac-02">Lois Griffin</option>
  </select>

您正在尝试在php中将字符串转换为int,因为htm代码中有字符串值,并且您正在尝试在php代码中将这些值转换为int,因此请相应地更正代码

如果html是

<select name="users" onchange="showUser(this.value)">
  <option value="">Select a person:</option>
  <option value="abc-01">Peter Griffin</option>
  <option value="aaac-02">Lois Griffin</option>
  </select>

您正在尝试以php返回字符串“abc-01”的intval

您正在尝试以php返回字符串“abc-01”的intval

您正在尝试以php返回字符串“abc-01”的intval

您正在尝试以php返回字符串“abc-01”的intval

您试图将字符串转换为int的值是什么?如果我选择“Peter Griffin”,则
echo$q
应该是
abc-01
您试图将字符串转换为int的值是什么?如果我选择'Peter Griffin',
echo$q
应该是
abc-01
您试图将字符串转换为int的值是什么?如果我选择'Peter Griffin',
echo$q
应该是
abc-01
您试图将字符串转换为int的值是什么?如果我选择'Peter Griffin',
echo$q应为
abc-01