在jQuery AJAX表单提交中使用数据库查询更新表


Updating table with database query on jQuery AJAX form submit

这是我所拥有的。。。

function checkDB(code, userid)
    {
      $("#notice_div").html('Loading..'); 
      $.ajax({
      type: "POST",
      url: "<?php bloginfo('template_url'); ?>/profile/check_code.php",
      data: { code: code, userid: userid},
      //data: 'code='+code+'&userid='+userid,
      datatype: "html",
      success: function(result){
           if(result == 0)
            {
                $('#success').html( code + ' has been redeemed!');
                // alert('success');//testing purposes
            }
            else if(result == 2)
            {
                $('#err').html(  code + ' already exists and has already been redeemed....');
                //alert('fail');//testing purposes
            }else if(result == 1){
                $('#err').html(  code + ' redeem code doesnt exist');      
            }
            $("#notice_div").html(''); 
            //$('#originalquery').hide();
            //$('#mainquery').fadeIn('slow');
            //$("#originalquery").replaceWith($('#mainquery', $(html)));
            //alert(result);        
          }
      })
    }

这与以下页面相同:

   <?php
$sql="SELECT * FROM wp_scloyalty WHERE userid = '$user_id'";
$result=mysql_query($sql);
?> 
<table id="poo" style="margin:10px 0px 0px 0px;" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><strong>Product</strong></td>
    <td><strong>Code</strong></td>
    <td><strong>Value</strong></td>
</tr>
<?php while($rows=mysql_fetch_array($result)){ ?>  
<tr>
    <td><? echo $rows['product']; ?></td>
    <td><? echo $rows['code']; ?></td>
    <td><? echo $rows['value']; ?></td>
</tr>  
<? } ?>
</table>

            <form method="post" class="sc_ajaxxx" id="sc_add_voucherx" name="sc_ajax" action="" onsubmit="checkDB(document.sc_ajax.sc_voucher_code.value, <?php echo $user_id; ?>); return false;">
            <button id="submit-code" type="submit" >Submit</button>
        </form>

这是HTML。。。

当提交ajax请求时,我希望表自动显示新添加的信息。我知道为什么它不起作用,但不知道如何让它刷新。我想刷新div并不像我希望的那样。我正在考虑创建一个新的查询,并将其引入成功函数?

谢谢:)

编辑

表格查询:

 <?php
$sql="SELECT * FROM wp_scloyalty WHERE userid = '$user_id'";
$result=mysql_query($sql);
?> 
<table id="poo" style="margin:10px 0px 0px 0px;" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><strong>Product</strong></td>
    <td><strong>Code</strong></td>
    <td><strong>Value</strong></td>
</tr>
<?php while($rows=mysql_fetch_array($result)){ ?>  
<tr>
    <td><? echo $rows['product']; ?></td>
    <td><? echo $rows['code']; ?></td>
    <td><? echo $rows['value']; ?></td>
</tr>  
<? } ?>
<div id="newCode"></div>
</table>

所以基本上你想从基于$user_id的数据库中提取记录,并且生成的表需要用ajax显示在请求页面上?正确的

显示新添加的信息

它是在哪里添加的?