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?
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.
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); } }
});
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
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.
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.
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':
is working on a reply...