【问题标题】:Passing id using jquery to URL使用 jquery 将 id 传递给 URL
【发布时间】:2015-01-14 09:19:23
【问题描述】:

我的故事板:

我有一个使用 php 从 mysql 查看数据的表。 每行都有一个按钮,用于将一行预览到模态引导程序中。

现在,我可以将数据的一个字段(也许是单元格)传递给 url 吗? 在我的情况下, no_request 将是一个参数。 因为这一字段将是一个参数

这是我的看法:

<table>
<tbody>
<?php
   $no = 1;
   foreach($data_request as $data) {
?>

<tr>
    <td class="center"><?php echo $no++.". ";?> </td>
    <td class="sorting1" id='no_request'><?php echo $data['code_office'].'/'.$data['code_departement'].'/'.date ('m', strtotime($data['month'])).'/'.$data['id_request'];?> </td>
    <td class="center"><?php echo "$name"; ?></td>
    <td class="center"><?php echo date ("d-m-Y, H:i ",strtotime($data['waktu_mulai']));?></td>
    <td class="center"><?php echo $data['complaint'];?></td>                                            
    <td class="center"><span class="label label-warning"><?php echo $data['status_request'];?></span></td> 
    <td class="center"><?php echo date ("d-m-Y, H:i ",strtotime($data['closing_request']));?></td>                                            
    <td  class="center">
        <a class="btn btn-danger" href="#">
            <i class="halflings-icon white trash"></i> Close
        </a>

        <a class="btn btn-success" href="#" id="print" req_id="<?php echo $data['id_request']; ?>">
            <i class="halflings-icon pencil"></i> Print  
        </a>         
    </td>
</tr>                                    

<?php } ?>
</tbody>
</table> 

    <div class="modal hide fade" id="myModal">

        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">×</button>
            <h1>Print Preview</h1>
        </div>

        <div class="modal-body">
           <p id="id_preview"> </p>
        </div>

        <div class="modal-footer">

            // This is the problem
            <a href="<?php echo base_url().'control_closing/generate_pdf/no_request ?>" class="btn btn-primary">Create PDF</a>
            <a href="#" class="btn" data-dismiss="modal">Close</a>   
        </div>

    </div>


    <script>
       $('.btn-success').click(function(e){
            e.preventDefault();

            var $this = $(this);

            var $trData = $this.closest('tr').clone();
            $trData.find('td:last').remove();

            var $thData = $this.closest('table').find('thead').clone();
            $thData.find('th:last').remove();

            var $table = $('<table border="2"></table>');
            $table.append($thData).append($trData);

            $("#id_preview").html($table);
            $('#myModal').modal('show');
        });

       function passing_id_to_url{
            //How to passing no_request to url ?
       }

    </script>

【问题讨论】:

    标签: jquery codeigniter url


    【解决方案1】:

    由于您使用的是 Jquery,并且我假设您想将数据 POST 回 URL,您可以使用隐藏表单:

    <form id="pdf<?php echo $no++;?>">
        <input type="hidden" name="office" value="<?php echo $data['code_office'];?>" />
        <input type="hidden" name="complaint" value="<?php echo $data['complaint'];?>" />
        ....
        <a class="btn btn-success" onclick="submit(<?php echo $no;?>)>Create PDF</a>
    </form>
    

    然后使用Ajax发布表单数据

    function submit(id) {
        $.ajax({
            url:'/control_closing/generate_pdf/no_request',
            type:'post'
            data:$('form#pdf'+id).serialize(),
            success:function(html) {
                modal(html);
            }
        });
    }
    
    function modal() {
       //.... Code for modal
    }
    

    【讨论】:

    • 谢谢戴夫。顺便说一句,我仍然很困惑。试试这个jsfiddle.net/UW38e,从那个url,你会看到,如何让'alert'上的文本作为参数发送到url。感谢之前
    猜你喜欢
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 2010-12-02
    • 2014-09-02
    相关资源
    最近更新 更多