我有一个通过PHP从MySQL数据库填充的数据表。第一列是标记功能,因此当单击任何特定行上的图钉图标时,数据库将更新为此字段的“y”或“n”。然后,我可以对此列进行排序,将所有标记的行放到表的顶部。由于我的表格相当大,我决定通过Ajax这样做。但是,它仅适用于第一个呼叫,然后变为非活动状态。第一次请求后数据库也不会更新。
这是HTML / PHP。
<td align="center" id="pin_record">
<?php // Flag Column
if ($row['flag'] == 'n'){ ?>
<a class="flag_image" href="list_all_quotes.php?id=<?php echo $row['quotes_id'].'_y'; ?>">
<img src="../images/flag_off.gif" border="0" width="17" height="17" alt="Flag Off">
<?php } elseif ($row['flag'] == 'y'){ ?>
<a class="flag_image" href="list_all_quotes.php?id=<?php echo $row['quotes_id'].'_n'; ?>">
<img src="../images/flag_on.gif" border="0" width="17" height="17" alt="Flag On">
<?php } ?>
</a>
</td>
这里是jQuery
function ajax_init()
{
$('#pin_record a:first-child').on("click",(flag_record));
}
function flag_record()
{
var id_pin = this.href.replace(/.*=/,'');
var id_array = id_pin.split("_"); // split the quote id and pin
var id = id_array[0];
var pin = id_array[1];
this.id = 'flag_link_'+id;
$.getJSON('deletequote.php?ajax=true&id='+id+'&pin='+pin,set_flag);
return false;
}
function set_flag(data)
{
if(!data.success)return alert(data.serverMessage);
var href = '<a class="flag_image" href="list_all_quotes.php?id='+data.id+'_'+data.pin+'">';
$('#flag_link_'+data.id)
.replaceWith(href+data.flagimg);
}
$(document).ready(ajax_init);
我是使用Ajax的新手,所以任何帮助都会非常感激。
非常感谢, 克里斯
答案 0 :(得分:2)
您的请求正在缓存中。使用唯一的URL中断缓存:
'deletequote.php?ajax=true&id='+id+'&pin='+pin,set_flag+"&now="+new Date()