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