drg14799 2017-03-27 20:37
浏览 40
已采纳

价值总是一定数量

The value of my id is always 10 ( the last number in my array).

This works fine for my jQuery function, but when using it with the value attribute: it always gives me 10 when doing the get request.

When inspecting my website : value is ok!
enter image description here

When doing a var dump : notice the second value.
enter image description here

I really need this to work to get to the other page.
I'm a bit stucked.

foreach ($data as $key => $value)
{

  if ($count % 4 == 0 && $count != 0)
  {
    echo "<div class=\"container\">";
    echo "<div class=\"row\">";
    echo "</div>";
    echo "</div>";
    echo "<br> <br>";
  }

  $id = $value['id'];
  echo "<div class=\"col-sm-3\">";
  echo "<form method='get' action='..\product\details' class='product-form'>";
  $img = $value["img"];
  $category = $value["category"];
  echo "<div class='panel panel-primary $category' >";
  echo "<div class='panel-heading'>".$value["name"]."</div>";
  echo "<div class='panel-body'><img src='../../public/img/$img' class='img-responsive' style='width:100%' alt='Image'></div>";
  echo " <div class=\"panel-footer\">".$value["description"]."<br><button type='button' class='btn btn-default cart-button'  onclick='addToCart($id)'><span class='glyphicon glyphicon-shopping-cart'></span></button></div>";
  echo "<input type='hidden' name='itemid' value='$id'>";
  echo "</form>";
  echo "</div>";
  echo "</div>";

    $count++;
}

To submit the form I use this:

$(function () {
    $(".col-sm-3").click(function test(event) {
        $(".product-form").submit();
    })
})
  • 写回答

1条回答 默认 最新

  • dongqie7806 2017-03-28 01:48
    关注

    Your server side code emits several forms, one per row.

    Your jquery will attempt to submit every form that has a CSS class of ".product-form", which means all of them. Each submit will cancel the previous (on most browsers, anyway), so the server only receives a request for the last one.

    I think you only want to submit one form-- the form that is a child of the DIV being clicked. So change your jquery:

    $(function () {
        $(".col-sm-3").click(function test(event) {
            $(this).find(".product-form").submit();
        })
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!