weixin_33736649 2014-04-11 20:41 采纳率: 0%
浏览 154

发送点击的按钮ID AJAX

I'd like to send series["id"+i] to write.php. (This code is in another ajax request.) Any idea?

series = new Object();
$(xml_node).find("Series").each(function (i) {
    series["id" + i] = $(this).find("seriesid").text();
    series["name" + i] = $(this).find("SeriesName").text();
    series["banner" + i] = $(this).find("banner").text();
    table += '<tr<td>' + series["banner" + i] + '</td>' + '<td>' + series["name" + i] +
        '</td>' + '<td>' + '<button>Add show</button>' + '</td>' + '</tr>';
});
$('button').click(function addseries() {
    $.ajax({
        type: "POST",
        url: 'write.php',
        data: series["id" + i],
        success: function (data) {
            console.log(data);
        }
    });
});
  • 写回答

2条回答 默认 最新

  • weixin_33720078 2014-04-11 20:43
    关注

    You can get the event of what triggered the ajax call,

    for example

    $('button').click(function addseries(e){
    console.log($(e.target));
    }
    

    where $(e.target) is the jQuery object that triggered the call.

    You can also use $(this)(referring to the jQuery object that called the function).

    so in our example,

    $('button').click(function addseries(e){
    console.log( $(this).attr('id') );
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器