这是我的......
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>
答案 0 :(得分:1)
所以基本上你想基于$user_id
从数据库中提取记录,并且生成的结果表需要在带有ajax的请求页面上显示?对?
显示新添加的信息
无论如何都要添加?