为什么我选择的选项没有被选中,结果也没有显示.我想使用ajax,jQuery来自动显示结果

Why my selected option is not selected and result is not displayed. I want to use ajax, jQuery to display the result automatically

本文关键字:结果 显示 ajax jQuery 选项 为什么 选择      更新时间:2023-09-26

我想自动显示所选选项,并且应该选择所选的选项,但既没有选择所选选项也没有显示结果。

<html>
<head>
<title>Untitled</title>
</head>
<body>
<table>
  <tr>
    <td>Name</td>
    <td width="151">
        <select id="jumpMenu" onChange="MM_jumpMenu(this.value)">
          <option value="">--Select Genre--</option>
          <option value="Action/Mission">Action</option>
          <option value="Racing">Racing</option>
        </select></td>
  </tr>
  <tr>
  <script type="text/javascript">
$(document).ready(function() {
    function MM_jumpMenu(eee){
    var val = document.getElementById("jumpMenu").value;
    if(val=="")
    {
    <?php $abc=mysql_query("select * from games order by game ASC"); ?>
    }
    if(val=="Racing")
    {
    <?php $abc=mysql_query("select * from games where genre='Racing' order by game ASC"); ?>
    }
    if(val=="Action/Mission")
    {
    <?php $abc=mysql_query("select * from games where genre='Action/Mission' order by game ASC"); ?>
    }
});
});
</script>
  <?php
while($row=mysql_fetch_array($abc))
{
?>
    <td><?php echo $row['game']; ?></td>
    <td><?php echo $row['genre']; ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>

问题出在哪里?

请记住,JS是客户端,PHP是服务器端。您无法同时运行这两者。但是,您可以使用ajax对服务器进行调用,并运行PHP脚本接收并使用JS中的响应。

参考:jQuery.ajax()| jQuery API文档