Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

SharePoint 2013 Rest Api - How to get List Items

$
0
0
 

Can anyone let me know why the below method fails? I am not getting where i am making mistake. Please help

function getListItems(term) {
            var caml = "<View><Query><Where><BeginsWith><FieldRef Name=Title/><Value Type='Text'>" + term + "</Value></BeginsWith></Where></Query></View>";
            var requestData = { "query": { "__metadata": { "type": "SP.CamlQuery" }, "ViewXml": caml } };

            $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getbytitle('SampleList')/Getitems",
                method: "POST",
                data:requestData,
                headers: {
                    "accept": "application/json; odata=verbose",
                    "content-type": "application/json; odata=verbose"
                },
                success: function (data) {
                    $("#countItem").html("Pass");
                },
                error: function (data) {
                    $("#countItem").html("Fail");
                }
            });
        }

Below is the responseText (log)

"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.ClientServiceException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The HTTP method \'GET\' cannot be used to access the resource \'GetItems\'. The operation type of the resource is specified as \'Default\'. Please use correct HTTP method to invoke the resource.\"}}}"


Navaneeth



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>