每当有人放置其他模型时,我怎么能追加另一个按钮

时间:2016-06-15 18:03:28

标签: javascript jquery ajax

每当有人为汽车制造商添加新数据时,我都会尝试附加一个新按钮。然而,它只是不断添加到同一个按钮。如何根据数据对新按钮进行操作?

$.ajax({
  method: 'GET'
  url: '/cars/'+ year + '/' + make_id,
  dataType: "json",
  success: function(data) {
    var model = data
    $('div#render-cars').append('<button id="car-model">' + model +  '</button>');
  }
});

1 个答案:

答案 0 :(得分:0)

试用此代码。相同的ID不能重复。改为使用类或使用动态ID

$.ajax({
             method: 'GET'
             url: '/cars/'+ year + '/' + make_id,
             dataType: "json",
             success: function(data){
                var model = data

                $('div#render-cars').append('<button class="car-model">' + model +  '</button>');