Php jqueryajax调用从MySql表设置select选项

Php jqueryajax调用从MySql表设置select选项,php,mysql,jquery,Php,Mysql,Jquery,我有一个DDL引擎,它需要根据所选的make DDL通过MySql表设置其选项值 我有以下传递到php文件的脚本-我知道php文件很好,因为我可以独立地输出查询结果 但是,我无法根据返回的数组获取要更新的选项值。。。可能是使用GET的结果?这是我第一次尝试通过AJAX返回,通常只是使用它来更新数据表等 我的剧本有什么不对劲吗 $(document).ready(function() { $("select#make").change(function(){ $('#engine').f

我有一个DDL引擎,它需要根据所选的make DDL通过MySql表设置其选项值

我有以下传递到php文件的脚本-我知道php文件很好,因为我可以独立地输出查询结果

但是,我无法根据返回的数组获取要更新的选项值。。。可能是使用GET的结果?这是我第一次尝试通过AJAX返回,通常只是使用它来更新数据表等

我的剧本有什么不对劲吗

$(document).ready(function() {

$("select#make").change(function(){
    $('#engine').find('option').remove().end(); //clear the engine ddl
    var make = $(this).find("option:selected").val(); //Need the value not the text

    $.ajax({
        url:'get-engine.php',
        type:'GET',
        data:{engine:make},
        dataType:'json',
        cache:false,
        success:function(data){


         var ddl = document.getElementById('engine');                      

         for(var c=0;c<obj.length;c++)
              {              
               var option = document.createElement('option');
               option.value = obj[c];
               option.text  = obj[c];                           
               ddl.appendChild(option);
              }


    },
        error:function(jxhr){
        alert(jxhr.responseText);

    }
    }); 

});
});
到目前为止,它拒绝更新,无法找到原因

提前感谢您的所有建议

您可以试试

//json is the json you have recieved in the success handler

$("#engine").empty();
$.each( json, function( index, item ) {
           $("<option/>",{value:item,text:item}).appendTo("#engine");

        });

你得到json响应了吗?你检查过firebug控制台了吗…嗨,是的,它检查过了,这很好-我可以在firebug中看到响应数组。。。按预期作为数组发送回来,只是我的脚本似乎没有根据返回的数组创建选项值?你能发布你的json响应吗?根据响应firebug选项卡,它返回为:[涡轮增压柴油机、涡轮增压汽油机、涡轮增压柴油机、涡轮增压汽油机]在for循环中查找obj的长度之前,不能将其设置为任何值。
//json is the json you have recieved in the success handler

$("#engine").empty();
$.each( json, function( index, item ) {
           $("<option/>",{value:item,text:item}).appendTo("#engine");

        });