Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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/4/sql-server-2008/3.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 window.XMLHttpRequest与script.change组合_Javascript_Jquery_Xmlhttprequest - Fatal编程技术网

Javascript window.XMLHttpRequest与script.change组合

Javascript window.XMLHttpRequest与script.change组合,javascript,jquery,xmlhttprequest,Javascript,Jquery,Xmlhttprequest,我在组合两个脚本时遇到问题。 First脚本工作正常,并从mysql获取stuf: <script type="text/javascript"> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (w

我在组合两个脚本时遇到问题。 First脚本工作正常,并从mysql获取stuf:

<script type="text/javascript">
 function showUser(str)
        {
        if (str=="")
          {
          document.getElementById("txtHint").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");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
            }
          }
        xmlhttp.open('GET','includes/test-search.php?q='+str,true);
        xmlhttp.send();
        }
    </script>

函数showUser(str)
{
如果(str==“”)
{
document.getElementById(“txtHint”).innerHTML=“”;
返回;
} 
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
open('GET','includes/test search.php?q='+str,true);
xmlhttp.send();
}
第二个脚本工作正常,它是一个简单的脚本,用于在更改后插入数据:

<script type="text/javascript">
    $("document").ready(function(){
        $("#selection").change(function () {
        $("#someDivName").html( $("#selection option:selected").val() );
    });
    });
    </script>

$(“文档”).ready(函数(){
$(“#选择”).change(函数(){
$(“#someDivName”).html($(“#选择选项:选定”).val();
});
});
现在,孔点是组合它们

看起来,当我加载站点时,它没有id选择,第二个脚本停止,但在从php和mysql文件test-search.php获取数据后,缺少的id选择在站点上,但第一个脚本没有检查id选择是否正确且不起作用

php代码:

<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("table", $con);
$sql="SELECT * FROM prod_models WHERE prod_main_group_id = '".$q."'";
$result = mysql_query($sql);
echo '
<select id="selection" name="prod_main_group_id" onchange="change_val()">
<option value="">Wybierz produkt</option>
';
while($row = mysql_fetch_array($result))
  {
  echo '<option value="'.$row['id'].'">';
  echo $row['product_name'] . "</option>";
  }
echo "</select>
";
mysql_close($con);
?>

显示已更改脚本的代码:

<input type="text" id="someDivName" value="" />

如果有人能帮忙解决这个问题,那就太好了。
Thx我现在正在等待,并试图自己解决这个问题,但现在我没有其他想法。

我不明白为什么您要使用ajax native,而另一方面,使用jquery。您可以在jquery上执行所有操作吗?onchange=“$(\'\35; someDivName\).val($(\'\35;选择选项:已选择\')).text()”>