Jquery POST刷新div

Paw*_*ary 0 php ajax jquery json

我想使用$.postjquery的函数进行div刷新,只有在修改了php脚本的json数据中返回的内容时.我知道ajax调用$.post永远不会被缓存.请帮助我$.post,或者$.ajax如果不可能使用$.post或任何其他可能的方法.

谢谢

Nic*_*tti 6

你为什么不缓存电话的响应?

var cacheData;
$.post({.....
         success: function(data){
                  if (data !== cacheData){
                     //data has changed (or it's the first call), save new cache data and update div
                   cacheData = data;
                   $('#yourdiv').html(data);
                   }else{
                   //do nothing, data hasan't changed
Run Code Online (Sandbox Code Playgroud)

这只是一个例子,您应该根据自己的需要(以及返回的数据结构)进行调整