这是我有...使用jQuery AJAX形式的数据库查询更新表提交
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>
你的html div是什么样的?成功提交后会发生什么?我假设你验证了你的代码正在被调用? Javascript应该能够在不刷新页面的情况下更新div。 – 2012-02-17 16:57:06
我添加了您提交的HTML表单。在提交时,只有两个div可以根据页面上显示的结果给出信息。我想要自动更新的div并不真正涉及到ajac ......它只是一个查询在同一页上.. – JamesG 2012-02-17 17:05:08