dsyua2828 2014-11-24 12:05
浏览 24

使用jquery为bootstrap模态赋予id,以便在sql查询中使用

I have a page where I need to have a "show function" where I click on a button, and then it will show the user information based on the id from the button.

I have this js code

$("#brugeridbtn").click(function(){

    var id = $("#brugerid").val();

    console.log( id );

    $.ajax({
        type: 'POST',
        url: 'test.php',
        data: { 
            'id': '1'
        },
        success: function(msg){
            alert('wow' + msg.id);
        }
    });

});

And this is my form

<form method='POST'>
 input type='hidden' name='brugerid' id='brugerid' value='$row[bruger_id]'>
 <button type='button' class='btn btn-info' id='brugeridbtn' name='test' data-toggle='modal' data-target='#myModal'>Open Modal With Form</button>
 </form>

Im stuck on how to get it to a $_POST so i can use it in the sql query.

  • 写回答

3条回答 默认 最新

  • 普通网友 2014-11-24 12:19
    关注

    Try putting the on the button like this

    <button type='button' class='btn btn-info' id='brugeridbtn' data-show-id='<?php echo $row['bruger_id']; ?>' name='test' data-toggle='modal' data-target='#myModal'>Open Modal With Form</button>
    

    And then

    $("#brugeridbtn").click(function(){
    
        var id = $(this).data('showId');
    
        console.log( id );
    
        $.ajax({
            type: 'POST',
            url: 'test.php',
            data: { 
                'id': id
            },
            success: function(msg){
                alert('wow' + msg.id);
            }
        });
    
    });
    

    I haven't given this a test, but the theory should work

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看