B
bizt
Hi,
Im currently looking to move into using JSON for AJAX instead of
returning from the server a string like the following:
12345{This is a text string{true[1234|This is another set of fields|
null
This is returned from the server and I use split() and loops to
generate JS arrays / nested arrays at the client end. I cannot use XML
is it is deemed to heavy for the website as we deal with very high
volumes of traffic and trying to reduce the data sent back and forth
through the client and servers. The problem with the above is that it
makes my life as a JS programmer harder coz I have to do all this
splitting and looping to seperate the data
Now JSON seems the perfect on both fronts - it is lightweight and I
only have to use a single eval() to replace what splits() and loops
done previously. I can also have as many levels and nesting as I wish.
There are a couple of conserns I have here tho:
Eval() I have heard can be quite slow? Is this a serious concern for
large data sets? Even if it is slow, is it still going to be faster
than my previous method above?
I understand that you can have a JSON format for JS arrays and JS
objects:
// array
{0: 12345,2:"This is a text string"}
// object
[12345,"This is a text string"]
I prefer objects because I dont need to specifiy the index key and I
can treat it exactly like an array - oSet[0] = ...
Are objects just as quick to access/alter as arrays? I have a few
simultaneous client processes going on (ie. refreshing multiple HTML
tables automatically in the background) and really want it to perform
well.
Is there anything else worth considering when using JSON? My website
is mainly just updating content on multiple tables and refreshing data
every so often, thats about the extent of it.
Thanks
Burnsy
Im currently looking to move into using JSON for AJAX instead of
returning from the server a string like the following:
12345{This is a text string{true[1234|This is another set of fields|
null
This is returned from the server and I use split() and loops to
generate JS arrays / nested arrays at the client end. I cannot use XML
is it is deemed to heavy for the website as we deal with very high
volumes of traffic and trying to reduce the data sent back and forth
through the client and servers. The problem with the above is that it
makes my life as a JS programmer harder coz I have to do all this
splitting and looping to seperate the data
Now JSON seems the perfect on both fronts - it is lightweight and I
only have to use a single eval() to replace what splits() and loops
done previously. I can also have as many levels and nesting as I wish.
There are a couple of conserns I have here tho:
Eval() I have heard can be quite slow? Is this a serious concern for
large data sets? Even if it is slow, is it still going to be faster
than my previous method above?
I understand that you can have a JSON format for JS arrays and JS
objects:
// array
{0: 12345,2:"This is a text string"}
// object
[12345,"This is a text string"]
I prefer objects because I dont need to specifiy the index key and I
can treat it exactly like an array - oSet[0] = ...
Are objects just as quick to access/alter as arrays? I have a few
simultaneous client processes going on (ie. refreshing multiple HTML
tables automatically in the background) and really want it to perform
well.
Is there anything else worth considering when using JSON? My website
is mainly just updating content on multiple tables and refreshing data
every so often, thats about the extent of it.
Thanks
Burnsy