dqrdlqpo775594 2017-04-19 10:52
浏览 116
已采纳

使用jquery将数据传递到新页面$ _POST

I have two tables and an input inside a form that more or less goes like this:

the table code (the two tables are the same, except for a slight difference in what table it calls):

<table cellpadding="0" cellspacing="0" class="paperTable searchResultContainer">
    <thead>
        <tr>
            <th>Name</th>
            <th>ID</th>
            <th>Company Reg.</th>
            <th>Postcode</th>
        </tr>
    </thead>

    <tbody>
        <?php while ($row = $items->fetch_assoc()) : ?>
            <tr class="row" data-address1="<?php echo $row['address1']; ?>"
                data-address2="<?php echo $row['address2']; ?>" data-address3="<?php echo $row['address3']; ?>"
                data-county="<?php echo $row['address4']; ?>" data-postcode="<?php echo $row['postcode']; ?>"
            >
                <td><?php echo (strlen($row['name'])           > 0 ? $row['name']           : '-'); ?></td>
                <td><?php echo (strlen($row['id'])             > 0 ? $row['id']             : '-'); ?></td>
                <td><?php echo (strlen($row['company_reg_no']) > 0 ? $row['company_reg_no'] : '-'); ?></td>
                <td><?php echo (strlen($row['postcode'])       > 0 ? $row['postcode']       : '-'); ?></td>
            </tr>
        <?php endwhile; ?>
    </tbody>
</table>

and my input is a simple one-liner checkbox that asks if none of the above matches the search..

what I'm trying to do, if the user clicks a table row, it posts the .data() attributes of the <tr> tag to the next step in the form, which is another page.

I've tried the hidden input idea, but because it's in a while loop where the inputs share the same name, the value of the input will be the last in the loop because it's last set. I've also tried ajax:

$.ajax({
    data:    $(this).data(),
    type:    'post',
    url:     'stepDos.php',
    success: function(data)
             {
                 window.location.replace('/path/to/stepDos.php');
             }
});

which didn't work when I var_dumped $_POST it returned empty.

I also tried a $.post function:

$.post('/path/to/stepDos.php', {data: data}, function(ev)
{
    window.location.replace('/path/to/stepDos.php');
});

again no avail - anything I'm missing?

Thanks

  • 写回答

4条回答 默认 最新

  • douxieshang5577 2017-04-19 12:02
    关注

    As I mentioned in the comment, you don't have to make one single form with all the data inside it.. Instead you can go for 1 form per row in a loop.

    This will give you the intended result!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab