繁体   English   中英

如何将ID作为查询字符串传递

[英]How to pass id as query string

当我点击编辑(href链接)时,我想重定向到新页面,我想获取与记录相对应的数据。 这是查看代码

<tr data-view-key="<?php echo $id; ?>">
    <td class=""><?php echo $id; ?></td>
    <td class=""><?php echo $article_type; ?></td>
    <td class=""><?php echo $abbr_article_type; ?></td> 
    <td class=""><?php echo $journal; ?></td>   
    <td class=""><?php echo $prefix_article_no; ?></td> 
    <td>
        <a href="" name="edit_article_type">Edit</a>
        |
        <a href="#<?php echo $id; ?>" name="delete_article_type">Delete</a>
    </td>
</tr>

这是js

    $(document).on("click", "a[name='edit_article_type']", function (event)
    {           
        event.preventDefault();
        window.location = "add-article-type-details";
    });

在控制器中,我想更新数据

用查询字符串发送:

$(document).on("click", "a[name='edit_article_type']", function (event){
    event.preventDefault();
    var id = $.trim($(this).closest('tr').find('td').eq(0).text());
    window.location = "add-article-type-details?id="+id;
});
$(document).on('click', 'td > button.myEditButton', function(){
    url = 'add-article-type-details';
    id  = $(this).closest('tr').data('view-key');
    window.location = url + '?id=' + id;
)};

编辑:由于您的id是表行中的数据属性,因此您可以监听<td></td>按钮的click事件。 事件发生时,它将从父<tr></tr>那里获取data-view-key属性,并重定向到给定的URL并将ID附加到该URL。

<tr data-view-key="<?php echo $id; ?>">
<td class=""><?php echo $id; ?></td>
<td class=""><?php echo $article_type; ?></td>
<td class=""><?php echo $abbr_article_type; ?></td> 
<td class=""><?php echo $journal; ?></td>   
<td class=""><?php echo $prefix_article_no; ?></td> 
<td>
    <a href=""<?php echo site_url('controller/function') ?>/<?php echo $id ;?>" name="edit_article_type">Edit</a>
    |
    <a href="<?php echo site_url('controller/function') ?>/<?php echo $id ;?>" name="delete_article_type">Delete</a>
</td>

您可以使用ajax,如需尝试此http://w3code.in/2015/10/how-to-edit-delete-and-update-data-without-refreshing-page-in-codeigniter/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM