Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

trying to learn client object model (ecma/js/jquery) approach to returning json data and working with that. below I will supply a quick example, but my question is basic context of how would I go about adding CAML (like you would if it was the spservice route)? or is it best practice to even use caml in an approach like this, versus something like just filtering and manipulating using jquery branching and such?

spservices is awesome, but I would like to learn other avenues particularly returning json to increase performance (seems to for me anyway).

appreciated as always guys!

share|improve this question

3 Answers 3

up vote 1 down vote accepted

There are really different ways to get data from your sharepoint lists. SPServices is awesome, indeed. Other ways are OData Services (_api i SP2013 _vti_bin i SP2013). There you can define json or xml as response format.

Another way to get your data from SharePoint is to use Client Object Model: CSOM. For a while ago I wrote a blog post about three way of getting list data through javascript:

Three ways to get the id of last created SPListItem

Hope, it helps.

share|improve this answer
    
@Anatoly....yes thanks! that does help. I was actually unaware of the parameter/query string syntax for the listdata.svc approach. do you know of a reference where I might find more examples to learn from of these...google isn't returning much in the way of this. thanks! –  Justin Jan 31 '13 at 17:26
    
Here is a good example on msdn and a detailed explanation –  Anatoly Mironov Feb 1 '13 at 9:54
1  
that is perfect...thanks. I am wondering why I couldn't find this in my searching even after you answered this but I suppose you don't really know what you are looking for until someone helps you along sometimes so thanks! –  Justin Feb 1 '13 at 11:21

Another approach I've started to use a bit more heavily is to create data view web parts that return JSON. This allows you to create whatever JSON output you need, have it rendered by the server and request it as needed via client side scripts.

http://www.metaengine.com/2012/12/Returning-JSON-from-the-SharePoint-DVWP-aka-poor-mans-GetSiteData

share|improve this answer
    
@PirateEric...thanks I will check this out a bit more. This is an approach I have never really seen before. Appreciated! –  Justin Jan 31 '13 at 17:28
    
Sure thing. The premise is you create a DVWP on a page and make it emit JSON, then in your client side script, you do an AJAX call to that ASPX page. You could even configure the DVWP to accept parameters and you could pass those along in the POST to fetch filtered data. –  PirateEric Jan 31 '13 at 18:25
    
yeah this is pretty cool, is it fast? I really like spservices and use it a lot, but am finding (for me) that the json listdata.svc method seems to be faster. I marked Anatoly's as the answer because I was looking for something specific to the listdata.svc, but in the case I wish I could accept both as answer. at any rate thanks again. –  Justin Feb 1 '13 at 11:23
    
In my use cases so far it's been pretty fast, a list of about 150 items. Maybe 75ms or so to fetch the data. –  PirateEric Feb 1 '13 at 16:31

Use CAML to get something close to what you want, and then consider JavaScript to fine tune it or make it dynamic. CAML will get translated to a database query and transfer only those items that are needed to the client, and for a single request will be more efficient than getting all the data and filtering it in JavaScript, particularly as lists get large.

You would not want to do JavaScript filtering on a thousand items when you only ultimately care about 3 of them; on the other hand, if you're doing something like filtering as text is typed in you don't necessarily want a new request to the server for each keystroke. There are things that cannot be done exactly in CAML, like regular expression matching.

share|improve this answer
    
no that totally makes sense, was thinking how could I use something like CAML/filtering in the listdata.svc returning json approach. was unaware that you could use query string parameters per anatoly's link through the url. thanks for the link though....regex = more stuff to learn! :) appreciated –  Justin Feb 1 '13 at 11:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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