1

i have a sharepoint list already created and populated from an excel file. How would i go about pulling data from sharepoint to a json object in my javascript program.

Another requirement is that the method be compliant with IE8 as that is the version currently running on all the computers that are to access it. the sharepoint list has 13 columns with around 100 rows. So it doesnt need much computational power.

i seem to have seen a few examples using rest queries but they were either too complex or dint seem to work in ie8 and sharepoint 2010

Sorry if the question is too simple, i just started using sharepoint and seem to be confused by the sheer amount of documentation involved.

0

This seems to work fine. Haven't tested in IE8 but I think it'll work.

function getData(siteurl) {
var endpoint = siteurl +"/_vti_bin/ListData.svc/ListName";
$.ajax({
url: endpoint,
method: "GET",
headers: {
    "Accept": "application/json; odata=verbose",
    "Content-Type": "application/json; odata=verbose"
},
success: function (data) {
     //data variable will have list json data
},
error: function (error) {
    alert(JSON.stringify(error));
}
});
}    
  • I tried the above code but what i seem to be getting in the console is html data of the page rather than the list items in json format. I am guessing this is due to the url being given in a wrong manner. This is how i have given it - sharepointsite.com/sites/sharepoint/test/Lists/SharepointList/… i even tried - sharepointsite.com/sites/sharepoint/test/Lists/SharepointList – C0d3ine Jul 27 '15 at 4:40
  • Yes, that is the wrong format. Endpoint URL must be http://sharepointsite.com/sites/sharepoint/test/_vti_bin/listdata.svc/SharePointList. This will query the listdata.svc web service and get you the list data. – Akhoy Jul 27 '15 at 4:55
  • Right i input the link as you suggested but now i am neither getting any data in the console nor am i getting an error message. The console is clean. The data is not displaying either. How to troubleshoot this ? --edit-- Hmm so after a minute i seem to be getting an error that says invalid argument and the location of this error is in the eval code. – C0d3ine Jul 27 '15 at 5:24
  • To check if the URL is correct, simply copy/paste the URL in the address bar. If data is displayed in the browser in XML format, URL is correct. If the URL is correct, you'll be able to retrieve it using JS. – Akhoy Jul 27 '15 at 5:34
  • I tried the link as you said but on pasting it in the browser it just says 404 not found which must mean the url is wrong in some manner. Maybe this will help - In the sherepoint site when i open the list the link is like this : sharepointsite.com/sites/sharepoint/test/Lists/sharepointList/… This link is what displays all the items of the list to me in sharepoint . – C0d3ine Jul 27 '15 at 6:10

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.