0

Have Migrated from SharePoint 2010 to SharePoint 2013, after migration xData.responseXML undefined. enter image description here

In SharePoint 2010 working fine with xData.responseXML, but not working in SharePoint 2013 itemCount value is showing undefined because the xData.responseXML is undefined.

var itemCount = $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount");

Please help on this issue.

0

I suggest you check the version of SPService library and jQuery library. The example code below for your reference.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "customlist",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
        if(Status=="success"){
            var itemCount=$(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount");
            alert(itemCount);
        }else{
            alert(xData.responseXML.xml);
        }
    }
  });
});
</script>

In SharePoint 2013, we can use REST API and jQuery Ajax to achieve the same requirement.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
    var listName="customlist";
    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('"+listName+"')/ItemCount",
        type: "GET",
        async:false,
        headers: {
            "Accept": "application/json;odata=verbose",
        },
        success: function (data) {
            var itemCount=data.d.ItemCount;
            alert(itemCount);
        },
        error: function (data) {
            alert(JSON.stringify(data));
        }
    });
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.