doupingzhi9674 2017-11-19 20:45
浏览 29
已采纳

从属选择Ajax jQuery Parser错误

I'm experiencing trouble with 2 level dependent dropdown.

When I select 1st dropdown, i have a PARSERERROR alert and second dropdown is not pouplated

Please, any advice about what's wrong?

Here is my code:

HTML

<div class="form-group">
<label>CLASSIFICATION<span class="text-danger">*</span></label>                                         
    <select name="document_classification" id="document_classification" class="select-search"  data-placeholder="">
    <?php
        $sql = "SELECT * FROM rm_document_classification_id"; 
                    $result = $mysqli->query($sql);
                    while($row = $result->fetch_assoc()){
                        echo "<option></option>";
                        echo "<option value='".$row['classification_id']."'>".$row['classification_description']."</option>";
                    }
        ?>
    </select>
</div>

<div class="form-group">
    <label>SUBJECTS<span class="text-danger">*</span></label>
    <select name="document_subject" class="form-control" style="width:350px">
     </select>
</div>

SCRIPT

$( "select[name='document_classification']" ).change(function () {
var class_id = $(this).val();
//alert(class_id);

if(class_id) {


    $.ajax({
        url: "ajax.php",
        type: "GET",
        dataType: 'json',
        data: {'classification_id':class_id},
        success: function(data) {
            $('select[name="document_subject"]').empty();
            $.each(data, function(key, value) {
                $('select[name="document_subject"]').append('<option value="'+ key +'">'+ value +'</option>');
            });
        },
        error: function (request,status, error) {
        console.log(error);
        alert(status);
    }
    });

}else{
    $('select[name="document_subject"]').empty();
}
});

PHP

<?
   include_once "../config.php";

   $sql = "SELECT * FROM rm_document_subject_id
         WHERE subject_classification_id LIKE '%".$_GET['classification_id']."%'"; 

   $result = $mysqli->query($sql);

   $json = [];
   while($row = $result->fetch_assoc()){
        $json[$row['subject_id']] = $row['subject_description'];
   }

   echo json_encode($json);
 ?> 

Thanks all. HID Thanks all. HID Thanks all. HID

  • 写回答

1条回答 默认 最新

  • douying2243 2017-11-19 21:00
    关注

    Please, remove in your php file:

    $json = [];

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化