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 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?