Working on classifieds website project and using and open source framework「osclass」,我試圖用AJAX api調用加載每個類別的計數,但有時它不會返回準確的結果PHP ajax API有些時候會返回錯誤的結果
例子: 總有效的車數據庫:71 但API刷新鉻緩存後返回68
我得到確切的數字:
這裏是我的簡單的API代碼:
$result = $con->query("SELECT pk_i_id FROM oc_t_item where pk_i_id in (select fk_i_item_id from oc_t_item_location where fk_i_region_id=$id) and fk_i_category_id=$cat and dt_expiration >= now() and b_enabled=1 and b_active=1") or die(mysql_error());
$count= mysqli_num_rows($result);
$array = mysqli_fetch_row($result);
}
else{
$result = $con->query("SELECT pk_i_id FROM oc_t_item where fk_i_category_id=$cat and dt_expiration >= now() and b_enabled=1 and b_active=1") or die(mysql_error());
$count= mysqli_num_rows($result);enter code here
$array = mysqli_fetch_row($result);
}
echo json_encode($count);
我認爲它的緩存相關的問題,但我不知道如何處理該問題,將不勝感激!
就在擡起頭。看起來您正在使用GET請求更新應用程序的數據庫/狀態。這就是問題出現的原因。有一個閱讀:http://stackoverflow.com/questions/4573305/rest-api-why-use-put-delete-post-get – 2014-11-06 08:44:21
謝謝你的回覆,我讀過這篇文章,但在我的情況下..我沒有使用任何API來更新數據庫中的狀態,僅使用它來讀取數據庫中的類別統計信息 – 2014-11-06 10:45:34
我在說一般情況。瀏覽器返回相同結果的唯一原因是因爲它被緩存(就像你自己所說的那樣)。如果在兩個GET請求之間沒有POST/PUT/DELETE,則服務器是SUPPOSE以返回相同的答案。 – 2014-11-06 10:47:33