weixin_33724059 2018-11-14 10:11 采纳率: 0%
浏览 30

在数据库中插入两个ID

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>

This is my input and button

<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>

Here input id comes from looping each post. The id values changing like example :

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

I'm passing these IDs in ajax but that id values are not changing.

  • 写回答

1条回答 默认 最新

  • weixin_33711647 2018-11-14 10:18
    关注

    try setting the hidden elements' value using the value attribute...

    <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>
    
    评论

报告相同问题?

悬赏问题

  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥15 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物
  • ¥15 osm下载到arcgis出错
  • ¥15 Dell g15 每次打开eiq portal后3分钟内自动退出
  • ¥200 使用python编写程序,采用socket方式获取网页实时刷新的数据,能定时print()出来就行。
  • ¥15 matlab如何根据图片中的公式绘制e和v的曲线图
  • ¥15 我想用Python(Django)+Vue搭建一个用户登录界面,但是在运行npm run serve时报错了如何解决?