Rest API 列表项目计数代码适用于 SP 2013 而不是 SPO
Rest API List item count code works on SP 2013 not SPO
下面用于计算列表中项目数的代码适用于 SP2013。但是当复制到 SPO 时,它失败了。
请查看下面的代码并提出建议。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function(){
$(function(){
var requestUri = "<<SITE URL>>/_api/web/lists/getbytitle('XYZ')/Items";
$.ajax({
url: requestUri,
type: "GET",
headers: {
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#_REQUESTDIGEST").val()
},
success: onSuccess,
});
function onSuccess(data) {
var itemsCount = data.d.results.length;
document.getElementById("ABC").value = (itemsCount);}
});
});
</script>
DDA Count: <input type="text" id="ABC" value="">
请修改代码如下:
<script type="text/javascript">
$(function(){
var requestUri = "https://zheguo.sharepoint.com/_api/web/lists/getbytitle('MyList9')/Items";
$.ajax({
url: requestUri,
type: "GET",
headers: {
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#_REQUESTDIGEST").val()
},
success: function(data)
{
console.log(data.d.results);
var itemsCount = data.d.results.length;
document.getElementById("ABC").value = itemsCount;
},
error: function(error)
{
console.log(JSON.stringify(error));
}
});
});
</script>
下面用于计算列表中项目数的代码适用于 SP2013。但是当复制到 SPO 时,它失败了。
请查看下面的代码并提出建议。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function(){
$(function(){
var requestUri = "<<SITE URL>>/_api/web/lists/getbytitle('XYZ')/Items";
$.ajax({
url: requestUri,
type: "GET",
headers: {
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#_REQUESTDIGEST").val()
},
success: onSuccess,
});
function onSuccess(data) {
var itemsCount = data.d.results.length;
document.getElementById("ABC").value = (itemsCount);}
});
});
</script>
DDA Count: <input type="text" id="ABC" value="">
请修改代码如下:
<script type="text/javascript">
$(function(){
var requestUri = "https://zheguo.sharepoint.com/_api/web/lists/getbytitle('MyList9')/Items";
$.ajax({
url: requestUri,
type: "GET",
headers: {
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#_REQUESTDIGEST").val()
},
success: function(data)
{
console.log(data.d.results);
var itemsCount = data.d.results.length;
document.getElementById("ABC").value = itemsCount;
},
error: function(error)
{
console.log(JSON.stringify(error));
}
});
});
</script>