dqoqnmb163241 2014-03-31 11:22
浏览 46
已采纳

使用Ajax / jQuery时提交php表单

I am trying to create something similar to a live auction, I am using Ajax/jQuery to basically refresh a embedded page to show any database changes (such as a new bid), this all works however, when trying to add a form to create a bid the form does not submit, how can I create a form that corresponds with the embedded page and updates the database accordingly.

What i've tried to far:

auctions.php:

<?php
if(isset($_POST['100k'])) {
echo "Bidded!";
}
?>
<div id="auctions">Loading Auctions, please wait...</div>

<script type="text/javascript">

setInterval(function()
{
   $.ajax({url:"/embeddedauctions.php", type:"GET", async:true, cache:false, success:function(result)
{
     $("#auctions").html(result);

}});

},1000);
</script>

embeddedauctions.php

    <?php
    if(isset($_POST['100k'])) {
    echo "Bidded!";
    }
    ?>

<table class="table table-bordered">
      <thead>
        <tr>
          <th>Name</th>
          <th>Start Price</th>
          <th>Buy Now</th>
          <th>Current Bid</th>
          <th>Bid</th>
        </tr>
      </thead>
      <tbody>

<?php
          $query = $db->query('SELECT * FROM auctions WHERE active = 1 ORDER BY endTime ASC') or die(mysqli_error($db));
          $num = $query->num_rows;
          if($num > 0) {

          foreach($query as $row) {
              $name = $row['name'];
          $startPrice = $row['startPrice'];
          $buyNow = $row['buyNow'];
          $currentBid = $row['currentBid'];

          echo '

          <form action="/auctions.php" method="post">
          <div id = "container">
                  <tr>
          <td>'.$name.'</td>
          <td>'.$startPrice.'</td>
          <td>'.$buyNow.'</td>
         <td>'.$currentBid.'</td>
          <td><input type="submit" class="btn btn-xs btn-success" name="100k" value="Bid +&pound;100k"></td>
          </tr>
          </form>
          ';

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

Is there any way to submit the form successfully while on auctions.php, currently it does nothing when I click the submit button, thanks!

  • 写回答

3条回答 默认 最新

  • doubo1871 2014-03-31 12:03
    关注

    auctions.php:

    <?php
        if(isset($_POST['field_name']) && ($_POST['field_name']==100K) ) {
        echo "Bidded!";
        }
        ?>
        <div id="auctions">Loading Auctions, please wait...</div>
    
        <script type="text/javascript">
    
        setInterval(function()
        {
           $.ajax({
               url:"/embeddedauctions.php", 
               type:"post",
               async:true,
               dataType:'html',
               data:'field_name=100k' 
               cache:false,
               success:function(result)
        {
             $("#auctions").html(result);
    
        }});
    
        },1000);
        </script>
    

    and the server page(embeddedauctions.php) change the first few lines two this

      <?php
        if(isset($_POST['field_name']) && ($_POST['field_name']==100K) ) {
        echo "Bidded!";
        }
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条