So just a simple tip in case anyone bumps into the same issue as I had a while back. Going from Beta to RTM, some things changed in the way you retrieve values using REST in the SharePoint 2013 client object model.
In the older versions of the object model, you could simply use something like this in your REST call:
$.ajax( { url: SPSearchResults.url, method: "GET", headers: { "accept": "application/json", }, success: SPSearchResults.onSuccess, error: SPSearchResults.onError } );
As you can see the headers is specifying application/json.
The fix is simply to swap that statement into this:
$.ajax( { url: SPSearchResults.url, method: "GET", headers: { "accept": "application/json;odata=verbose", }, success: SPSearchResults.onSuccess, error: SPSearchResults.onError } );
And that’s a wrap.
Summary
I hope this can save someone a few minutes (or more) of debugging for using old example code or ripping up older projects. I’ve found that a lot of examples online, based on the beta of SharePoint 2013, are using the older version of the headers-statement which inevitably will lead to this problem. So with that said, enjoy.
Comments are closed
Archived comments
This was my problem! I saw that ‘odata’ entry in some other documentation, and foolishly ignored it, thinking I knew better. Lesson learned ;-) Thanks!
Wohoo! Glad it worked out Rob! :-)
Tobias.
Thank you sir. Kind of after the fact for me. But nonetheless, this was a big help. Short story...I was using the SharePoint 365 environment for my development. Abandoned the REST api because I could not get it to working. Thought it had something to do with the online environment. Once we moved it in-house and I still had this problem that's when I knew it had to be something different. I am disappointed Microsoft didn't communicate this.
Thanks again, for sharing the knowledge!
After searching for this exact term...I found some Microsoft articles that do mention how to do this. Using "verbose". However, their video demos show the old way. I guess I should of dug deeper. Was on a tight schedule and just used the CSOM.
Hi Xavier,
The issue about demo videos showing the old way is unfortunately a result of the demos being recorded during the beta period, something we'll have to take into account when working with beta products :-)
I'm glad you worked it out in the end.
Cheers,
Tobias.
This saved me a lot of headache. Thanks for posting this.
You're most welcome Paul.
Cheers,
Tobias.
Lifesaver! Thanks for posting this!
Rock and roll Neha!
Thanks Tabis, for brilliant post!
Saved me a lot of time, owe you a beer ;)
Cheers,
Hi Parry,
No worries - glad you found it useful.
Cheers,
Tobias.
Excellent! Couldn't figure out why copying exact video sample was causing an error. Thanks for sharing this!
Awesome, glad it works mate.
Cheers,
Tob.
Thanks! After 4 hours of debugging, I found this solution which saved me :) Had to fix it in my jquery1.7.1.js file.