Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1288 posts 3921 karma points c-trib
    Mar 21, 2013 @ 18:36
    Dan
    0

    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!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 21, 2013 @ 22:13
    Jan Skovgaard
    101

    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

  • Dan 1288 posts 3921 karma points c-trib
    Mar 22, 2013 @ 08:33
    Dan
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft