Copied to clipboard

Flag this post as spam?

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


  • Sander Houttekier 114 posts 163 karma points
    Oct 29, 2010 @ 17:46
    Sander Houttekier
    0

    Base with Json

    after watching the base movies (which opened my eyes on the posibilities with base) I noticed Per saying you could use it even with Json instead of xml,

    I could not find that many info on it though. so I started fearing he was talking about just outputting a string of json content, and using the Eval parse functionality in javascript to parse it to Json,

    If so that would not be a very good idea as the eval is a real performance killer
    anyone know how to use json output in base?

     

    best regards

    Sander

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Oct 29, 2010 @ 18:08
    Lee Kelleher
    0

    Hi Sander,

    Have a read over Sebastiaan's blog post about it:

    http://www.cultiv.nl/blog/2010/10/12/using-base-to-create-and-consume-a-json-string

    ... but he's using eval() too! ;-)

    Cheers, Lee.

  • Sander Houttekier 114 posts 163 karma points
    Nov 05, 2010 @ 22:58
    Sander Houttekier
    1

    that is what i feared,

    I really try to use eval as few as possible, though i have to admit, sometimes it can make your day so much easier :)
    though in my case i have to fetch data from a service so i have no control on the data itself, i do a few magic tricks with it and then return it trough base to the front end.

    So i can see Eval beeing a bad idea here, as the data could always contain harmful data.

    eval is perfectly fine though in a case where you have total control over the data you are returning, if you created it yourself, without the posibility of users entering possible harmful data trough text input or so, (and if your site is not that attractive to hackers :P)

     

    in any case, thanks for the link Lee it did show that eval is the way to go, though I'd like to remind people to use with care.

  • James Telfer 65 posts 165 karma points
    Dec 22, 2010 @ 06:42
    James Telfer
    1

    FWIW, in more recent versions of JQuery, it's better to use the parseJSON method. This is used implicitly in the getJSON method, and also when you pass dataType: 'json' to the ajax method.

    This means that a simpler and more secure version of Sebastians (very useful) example would be to replace the 'ajax' call with 'getJSON':

    $.getJSON(getFormUrl, function (data) {
      // operate directly on data as the JS object 
      if (data) { for (var i = 0; i < data.length; i++) { alert(data[i].Name); } }
    });
Please Sign in or register to post replies

Write your reply to:

Draft