我使用PHP根据结果集更新项目表。
while (!$rs->EOF) {
$conn->Execute("UPDATE [table] SET qty='".$quantity."' WHERE
locn ='".$locn."' AND pdln ='".$pdln."'");
echo "Item updated...<br/>"; /////////Message display here
$rs->MoveNext();
}
由于数据量非常大,我希望在每次成功更新一行后,向用户显示一条消息。有没有办法使用Ajax或Jquery来实现这个目标?
答案 0 :(得分:1)
if (ob_get_level() == 0) ob_start();
while (!$rs->EOF) {
$conn->Execute("UPDATE [table] SET qty='".$quantity."' WHERE
locn ='".$locn."' AND pdln ='".$pdln."'");
echo "Item updated...<br/>"; /////////Message display here
ob_flush();
flush();
sleep(1);
$rs->MoveNext();
}
echo "Done.";
ob_end_flush();
答案 1 :(得分:1)
基于我的理解
while (!$rs->EOF) {
$conn->Execute("UPDATE [table] SET qty='".$quantity."' WHERE
locn ='".$locn."' AND pdln ='".$pdln."'");
echo TRUE; // You can return False if row didn't update if you want
$rs->MoveNext();
}
在HTML中,使用jQuery函数.ajax()
或使用Javascript。
$.ajax
({
url: "<?php echo site_url();?>/site/bookmark/"+$bookmark_button.parent().attr('id'),
type: "GET",
success: function(data)
{
switch ( data )
{
case TRUE:
console.log('Item updated successfully '); // Change the way it's displayed as you like
break;
case FALSE:
console.log('Item did not update successfully '); // Change the way it's displayed as you like
break;
}
},
error: function(data)
{
console.log('Error updating item, connection error maybe?'); // Optional
}
});