gpt4 book ai didi

javascript - 在数据库中插入两个ID

转载 作者:行者123 更新时间:2023-12-03 00:44:43 24 4
gpt4 key购买 nike

Ajax :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
$(document).ready(function(){

$("#button").click(function(){
var insPer =$("#insPer").val();
var insPos =$("#insPos").val();
$.ajax({
url:'../validate/inspire.php',
method:'POST',
data:{
u_id:insPer,
p_id:insPos
},
success:function(data){
//alert(data);
}
});
});
});
</script>

这是我的输入和按钮

<span class="views" data-toggle="tooltip" title="Inspired">
<input type="hidden" id="insPer<?php echo $p_id; ?>" name="insPer">
<input type="hidden" id="insPos<?php echo $p_id; ?>" name="insPos">
<a href="#" role="button" id="button<?php echo $p_id; ?>" type="submit">
<img src="../images/lightbulb-regular.svg" class="like-btn-svg">
</a>
</span>

这里的输入 id 来自循环每个帖子。 id 值变化如下示例:

loop1 {insPer1,insPos1,button1},  
loop2 {insPer2,insPos2,button2},

我在 ajax 中传递这些 ID,但 id 值没有改变。

最佳答案

尝试使用 value 属性设置隐藏元素的值...

<span class="views" data-toggle="tooltip" title="Inspired">
<input type="hidden" id="insPer" name="insPer" value="<?php echo $p_id; ?>" />
<input type="hidden" id="insPos" name="insPos" value="<?php echo $p_id; ?>" /> <-- assuming $p_id should be the value of this input element -->

<a href="#" role="button" id="button" type="submit">
<img src="../images/lightbulb-regular.svg" class="like-btn-svg">
</a>
</span>

关于javascript - 在数据库中插入两个ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53297684/

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