避免AJAX缓存

  使用AJAX取后台数据,按要求每次应该返回的是不同的结果,但由于缓存,经常会出现两次取的数据重复的问题。特从网上寻觅解决方法:

  1、在服务端加 header(“Cache-Control: no-cache, must-revalidate”);

  2、在ajax发送请求前加上 anyAjaxObj.setRequestHeader(“If-Modified-Since”,”0″);

  3、在ajax发送请求前加上 anyAjaxObj.setRequestHeader(“Cache-Control”,”no-cache”);

  4、在 Ajax 的 URL 参数后加上 “?fresh=” + Math.random(); //当然这里参数 fresh 可以任意取了

  5、和第4种类似,只不过把参数换成时间。因为毕竟随机数还是存在重复的可能性,如果换成时间就不可能重复了。在 URL 参数后加上 “?timestamp=” + new Date().getTime();

  6、用POST替代GET:不推荐


( ! ) Warning: Missing argument 1 for cwppos_show_review(), called in /data/www/enjoyphp/wp-content/themes/flat/content-single.php on line 29 and defined in /data/www/enjoyphp/wp-content/plugins/wp-product-review/includes/legacy.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0000355192{main}( ).../index.php:0
20.0001355480require( '/data/www/enjoyphp/wp-blog-header.php' ).../index.php:17
30.214410158944require_once( '/data/www/enjoyphp/wp-includes/template-loader.php' ).../wp-blog-header.php:19
40.215710230088include( '/data/www/enjoyphp/wp-content/themes/flat/single.php' ).../template-loader.php:74
50.303810817800get_template_part( ).../single.php:5
60.303810818320locate_template( ).../general-template.php:167
70.303810818416load_template( ).../template.php:643
80.303810818800require( '/data/www/enjoyphp/wp-content/themes/flat/content-single.php' ).../template.php:686
90.309310803536cwppos_show_review( ).../content-single.php:29

1 评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注