Updating list of <select> options using jquery and ajax

前端 未结 2 906
陌清茗
陌清茗 2020-12-16 00:47

I am trying to make an html select list of options update according to a selection made on a prior html select object. My jquery is below. This is being called correctly.

2条回答
  •  心在旅途
    2020-12-16 00:51

    You can use $.getJSON if your expecting a json response. You might also be able to use $.each() and then simply .append() to the select tag. You can reference this.property inside the .each().

    Something like the following:

    $.getJSON("updateTypes.php?q="+brandName, function(data) {
        $("#Type").html('');
        $.each(data, function(){
            $("#Type").append('')
        )
    })
    

    This would assume your json response is something like the following:

    [ { name : "foo", value : "bar" }, { name : "another", value : "example" } ]

提交回复
热议问题