1

I am using SharePoint 2013 on-prem.

I am having a problem with my XMLHttpRequest. I do not want to use a jQuery wrapper so I need help getting the below to work. How do I get to the data? Also, my count seems to be wrong. It return 3000 as the length. I'm just trying to return the number of SharePoint list items the call returned. Any help would be much appreciated.

var itemID = getQueryString("ID");
                            var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbyTitle('Document Approval')/items?$filter=(BackToAD eq 'Yes') and  (ID eq "+ itemID + ")";
                            console.log(endPointUrl);

                            var xReq = new XMLHttpRequest();
                            xReq.open("GET", endPointUrl, true);
                            xReq.setRequestHeader("Accept", "application/json; odata=verbose");
                            xReq.timeout = 2000;
                            xReq.ontimeout = function(){
                                            alert("timeout");
                            }
                            xReq.onreadystatechange = function() {
                                            if (xReq.readyState === 4){
                                            //alert("IN onready");
                                                            if (xReq.status === 200){
                                                                console.log("LENGTH: ");
                                                                            console.log(xReq.response.length);
                                                                            console.log("Text: ");
                                                                            //console.log(xReq.responseText);
                                                                            console.log(xReq.target.responseText);

                                                            } else {
                                                                            console.log("Fail");
                                                            }
                                            }
                            }
                            xReq.send();
3
  • The xReq.responseText will have the json that will return your data. You then need to iterate through the json to get the data. Aug 6, 2018 at 6:10
  • Even if it is returning 1 value?
    – OLA
    Aug 6, 2018 at 17:48
  • But that one value will have the json which will have all the data you have requested. If not then run this url var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbyTitle('Document Approval')/items?$filter=(BackToAD eq 'Yes') and (ID eq "+ itemID + ")"; in the browser to check how many values it is returning or you can also use postman for it Aug 7, 2018 at 5:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.