Resolve the ajax caching problem in jquery

  • 2020-03-30 01:01:06
  • OfStack

Jquery's ajax request requires that the cache be true by default, which is enabled, and that the dataType be false by default for script and jsonp. Now I'm going to read the cache in the browser, because the ajax requests are so big that one request is enough. The problem is that in FF, there is no ajax cache, which means that every time an ajax request is triggered, unlike in IE. So it's important to make a decision here to prevent the ajax event from being triggered.

function ajax_show(apartId,roomClass,sortTile){
          HX_THIS_FANGXING_NUM=sortTile;
          huxing_pic_set_color();    
          var this_li=$('#title_'+sortTile);
          var cache=this_li.data("cache");
          if(undefined!=cache){
           var data_arr =cache.split('-');
            xg_pic_links=data_arr[0];//Cache record
            layout_pic_links=data_arr[1];
            layout_big_pic_links=data_arr[2];
            product_links=data_arr[3];
               xg_pic_deal_array();
            xg_show_pic(xg_now_pic_id);
            }else{
                   $.ajax({//The JQ cache will still make a new request under FF
                    type: "POST",
                   url: "index.php?m=content&c=index&a=ajax_all_pic",
                  data: "apartId=123&roomClass=123",
                 dataType:'text',
                  success: function(backdata){
                       this_li.data('cache',backdata);//Cache record     
                       var data_arr =backdata.split('-');
                       xg_pic_links=data_arr[0];    
                       layout_pic_links=data_arr[1];
                       layout_big_pic_links=data_arr[2];
                       product_links=data_arr[3];
                       xg_pic_deal_array();
                       xg_show_pic(xg_now_pic_id);             
               }
           });

          } 
    }

Through this_li. Data (' cache 'backdata); // cache records to mark

Related articles: