I'm building an umbraco /base extension which is called by AJAX. The javascript is expecting the returned data in JSON format. Question is, should I just return a string from the base call or should I return a 'proper' JSON object? If the latter, then how do I do that (I've tried setting the type through the HTTPContext but that doesn't work)?
Thanks Jan. I'd seen that blog post but it suggests returning a string rather than a JSON object. I thought that the Javascript would require that it's served as a JSON object, but actually, having tried it now, it seems to accept a string without any problem.
Return JSON or string from /base extension
Hi,
I'm building an umbraco /base extension which is called by AJAX. The javascript is expecting the returned data in JSON format. Question is, should I just return a string from the base call or should I return a 'proper' JSON object? If the latter, then how do I do that (I've tried setting the type through the HTTPContext but that doesn't work)?
Thanks!
Hi Dan
I think you should be able to benefit from this blogpost by Sebastiaan http://www.cultiv.nl/blog/2010/10/12/using-base-to-create-and-consume-a-json-string
If you prefer using Razor Seb also wrote another article about using that to achieve the same thing http://cultiv.nl/blog/2011/7/25/razor-vs-base-to-output-json-in-umbraco/
Hope this helps :)
/Jan
Thanks Jan. I'd seen that blog post but it suggests returning a string rather than a JSON object. I thought that the Javascript would require that it's served as a JSON object, but actually, having tried it now, it seems to accept a string without any problem.
is working on a reply...