ajax元素怎么添加,添加ajax请求到元素附加上一个AJAX请求

我有一个类别列表,当客户端从列表中选择一个新的列表创建下面与该类别的子项,现在我需要添加另一个级别(另一个列表),但我不知道如何。 这应该工作,但我想脚本不能知道元素是否存在或不存在。添加ajax请求到元素附加上一个AJAX请求

到目前为止,我的JS是这样的:

// when the user clicks on a drop down item from the list it adds a new drop down list

$('#cat_select_1').on('change', function() {

// fetch second list from the other script

var fetchUrl = 'http://localhost/includes/ajax/list-of-cats.php?catid=';

var fetchCatId = $("#cat_select_1").val();

// if the second list is there

if ($("#cat_select_2").length){

// replace it with the new one

$.get(fetchUrl.concat(fetchCatId)).done(function(data) { $("#cat_select_2").html(data); });

}

else {

// otherwise append this one

$.get(fetchUrl.concat(fetchCatId)).done(function(data) { $("#jumbocats").append(data); });

}

});

//list #2 (not working)

$('#cat_select_2').on('change', function() {

// fetch third list from the other script

var fetchUrl = 'http://localhost/includes/ajax/list-of-cats.php?catid=';

var fetchCatId = $("#cat_select_2").val();

// if the third list is there

if ($("#cat_select_3").length){

// replace it with the new one

$.get(fetchUrl.concat(fetchCatId)).done(function(data) { $("#cat_select_3").html(data); });

}

else {

// otherwise append this one

$.get(fetchUrl.concat(fetchCatId)).done(function(data) { $("#jumbocats").append(data); });

}

});

它适用于第一个列表中,但它不会为第二个列表工作。

我错过了什么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值