首页 > 代码库 > REST实现页面访问量查询修改

REST实现页面访问量查询修改

//总浏览量
function SeachTotalCount(){
    var par = encodeURIComponent("统计");
	 $.ajax({
	 
       url:  "/_api/web/lists/getbytitle(‘"+ par +"‘)/items?$select=Title,ID,Count&$filter=ID eq 4",
      type: "GET",
      headers: { "accept": "application/json;odata=http://www.mamicode.com/verbose" },
      success: function(data){
     	    var articleresults = data.d.results;
            UpdateTotalCount(articleresults[0].Count+1)      
           
      },
      error:onError
      });

}
//修改统计数
function UpdateTotalCount(count){   
    var par = encodeURIComponent("统计"); 	
  	var url="/_api/Web/Lists/GetByTitle(‘"+par+"‘)/Items(4)";
    var data = {
			    __metadata: { ‘type‘: ‘SP.Data.StatisticsListItem‘ },
			    Count: count
       	};
	 $.ajax({	 
       url:  url,
       type: "POST",
       data: JSON.stringify(data),
       headers: { 
            "X-HTTP-Method":"MERGE",
            "accept": "application/json;odata=http://www.mamicode.com/verbose",
            "content-type": "application/json;odata=http://www.mamicode.com/verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "IF-MATCH": "*"
        },
        error: one rror 
        });

}

  技术分享

 

REST实现页面访问量查询修改