簡體   English   中英

使用新接收的data.id更新AJAX / PHP VAR

[英]Update AJAX/ PHP VAR with newly received data.id

因此,在對我的數據庫的AJAX首次調用中,我使用Ajax var作為php變量

像這樣var notification_id="<?php echo $notification['notification_id']?>";

但是,在第一次調用之后。如果僅收到新數據,那么如何從成功發送回新的notification_id以替換該var? 目前,具有相同notification_id的同一呼叫正在不斷進行。 但是,可以說有人由於某種原因刪除了通知或進行了更新,初始調用將不再是最大notification_id,因此顯然必須進行更改。

因此,我進行了一些研究,並發現了這是我認為對其進行了更新的內容。 只有我將其放入成功的每個循環中,但沒有任何反應。

notification_id = notification.notification_id;

客戶端AJAX

success: function(response){
       $.each(response.notification, function(i, notification) {
  if(notification.notification_id > notification_id){
$("#newnotif"+ notification_id).prepend('MY CONTENT');
      i = parseInt($("#mes").text()); $("#mes").text((i+notification.num));
  }
  notification_id = notification.notification_id; 
            });

        }

好吧,我已經解決了。

問題是我將函數放在變量之外,而不在變量之下。 而且我還沒有把notification_id = notification.notification_id; 在每個循環中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM