【问题标题】:query Fetch data from multiple tables MySQL查询 MySQL 从多个表中获取数据
【发布时间】:2015-02-10 19:01:08
【问题描述】:

我有一个页面,其中有一个表单,其中有两个单选按钮,选择相关按钮中的一个,其相关内容将显示在表单上。

<tr class="text">
<td colspan="4" valign="top" bgcolor="f2f2f2">
<?php
$srl=mysql_query("select * from module ORDER BY module_id ASC");
while($rows=mysql_fetch_array($srl))
{ ?>
<input type="radio" name="module" value=<?php echo $rows[module_id] ?>><?php echo $rows[module_name] ?>
<?php
}
?>
</td>
</tr>
</tbody>
</table>

<tr class="text">
<td colspan="6">
<div id="items_list"></div>
</tr>

我已经为 api 调用编写了这个 jquery。

<script type="text/javascript">
                $(function() {
                $("module").change(function() {
                var module_id = $(this);
                var dataString = 'module_id='+  module_id.val();
                alert(dataString);
                $("#items_list").html("");
                if(module_id.val()=='')
                  {
                     alert("select stock type");
                   }
                else {
                                $.ajax({
                                type: "POST",
                                url: "ajax/request_fetch_items.php",
                                data: dataString,
                                cache: false,
                                success: function(){
                                    $("#items_list").html( html );
                                },
                                error:function (xhr, ajaxOptions, thrownError){
                                        //On error, we alert user
                                            alert(thrownError);
                                            }
                                });
                }
                return false;
                });
                });
                </script>

但是当我选择任何单选按钮时没有任何反应,它也不会在 jquery 中显示警报。 what i want is whenever a radio button is selected, its value is passed via ajax call, the the remaining html content will be load into the next row.

在插入单选按钮时,它会显示以下代码,

<input type="radio" name="module" value="1">Stationary  
<input type="radio" name="module" value="2">Inventory   

【问题讨论】:

  • 您检查控制台是否有错误?
  • 控制台上显示此错误Uncaught SyntaxError: Unexpected token else
  • 我不确定带有单选按钮的 HTML 部分是否良好,使用控制台检查单选按钮的 html 并粘贴
  • @MuhammadTaqiHassanBukhari 这个错误似乎不言自明。
  • 我已经解决了控制台中的Uncaught SyntaxError: Unexpected token else错误,没有控制台中没有错误和警告。但仍然没有打电话,也没有警报。

标签: php jquery mysql ajax radio-button


【解决方案1】:

您的 jQuery 选择器 $("module") 的目标是 &lt;module&gt; html 标记,只需将其更改为 $("input[name=module]:radio"),以便它指向名为模块的无线电类型的 &lt;input&gt; 元素。

https://jsfiddle.net/eh6c5wjb/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    相关资源
    最近更新 更多