我使用jQuery.get()
從頁面中刪除表中的行main.php
。現在我想刪除一行之後,顯示成功的消息,那成功的消息應該在會話變量($_session['suxesMsg']
)如何使用jquery.get()方法在會話變量中返回成功消息
- 如何在一個會話變量設置成功的消息,並顯示在特定的範圍?
或
- 有jQuery中的任何其它方法,一個消息顯示爲只有5-10 秒,然後消失?
這裏是我的代碼
main.php
<?php if($_SESSION['suxesMsg']!='') { ?>
<span class="msg">
<?php echo $_SESSION['suxesMsg'];unset($_SESSION['suxesMsg']); } ?>
</span>
<table border="0" cellpadding="5" cellspacing="0" id="promotionTable">
<tr>
<td align="left"><img border='0' src='images/just.gif'/>First Promotion</td>
<td align="center" >View Detail</td>
<td align="center" id="deleteMe">
<img src='images/delete.png' alt='Delete' width='14' height='14'id="45"/>
</td>
</tr>
<tr>
<td align="left"><img border='0' src='images/just.gif'/>First Promotion</td>
<td align="center" >View Detail</td>
<td align="center" id="deleteMe">
<img src='images/delete.png' alt='Delete' width='14' height='14' id="48"/>
</td>
</tr>
</table>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#deleteMe img').click(function() {
if(!confirm('Want to delete!')) return;
jQuery.get('deleteThis.php', {oid:this.id});
jQuery(this).parent().parent().fadeTo(400, 0, function() {
jQuery(this).remove();
});
});
</script>
deleteThis.php
if(isset($_GET[oid]))
{
$offerID=$_GET[oid];
$delsql="DELETE FROM some_table WHERE promotion_id=".$offerID;
$db->query($delsql);
$_SESSION['suxesMsg'] = "Promotion deleted sucessfully.";
}
感謝您的幫助alwayz
作爲,看到http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol:「請注意,GET不應該用於引起副作用的操作,例如用於在Web應用程序中執行操作,其中一個原因是GET可以被機器人或爬蟲程序任意使用,而不需要考慮請求應該引起的副作用「。 – 2010-04-30 12:58:34
感謝您的建議,但我需要解決方案先生 – diEcho 2010-04-30 13:19:24
@我喜歡PHP:對不起,我的評論的解決方案是使用POST進行操作,導致副作用。 – 2010-04-30 13:27:16