gpt4 book ai didi

jquery - 在ajax中引用 anchor 标记

转载 作者:行者123 更新时间:2023-12-01 04:36:42 26 4
gpt4 key购买 nike

我收到了 Array包含 jinja2 的项目来自 <a> 中的数据库标签,item[0] 代表一个 id,而 item[1] 是一个属性(例如名称)。
我想引用我的ajax中的id如果我点击 anchortag 中的任何内容,请调用它引用了 id,现在一旦我单击 anchortag 中的任何内容,一切都在不引用 id 的情况下运行

HTML

{% for item in people %}
<a id="foo" class="foo">{{item[1]}}</a>
{% endfor %}

JAVASCRIPT/AJAX

{% for item in people %}

$(".foo").click(function(evt) {
$.ajax({
url: "/~s6/cgi-bin/people.py",
async: true,
type: "post",
datatype:"json",
data: {'peopleid': {{item[0]}}},
success: function(result) {
console.log(result)
//console.log(result.peopleinfo.surname)
// console.log(result.peopleinfo.othernames)
console.log(result.familyinfos)

html = "<table class='table table-striped table-bordered table-condensed'>" + "<tr><th>Old Name</th><td>" + result.peopleinfo.surname + "</td></tr>"' + "<table>"

$('#infoTab').html(html)

$("#placenameModal").modal("show");
}

});


});
{% endfor %}

最佳答案

也许是这样的:

HTML

{% for item in people %}
<a id="{{item[0]}}" class="foo">{{item[1]}}</a>
{% endfor %}

Javascript

$(document).on('click', '.foo', handleClick)
function handleClick(e) {
$.ajax({
url: "/~s6/cgi-bin/people.py",
type: 'POST',
data: {
peopleid: $(this).attr('id')
},
success: handleModal
})
}
function handleModal(response) {
// Do stuff here with your response
}

关于jquery - 在ajax中引用 anchor 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51155785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com