这是我所拥有的...
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显示在请求页面上?正确的?
show the newly added information
它到底添加到哪里了?
关于php - 在 jQuery AJAX 表单提交上使用数据库查询更新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9332238/