Skip to content

Can’t help myself…

by chris on May 25th, 2010

So, I’ve been developing this jQuery chat thing, and it’s been teaching me so much about efficient data transfer and good API design. I have to say that I am by no means a David Walsh or an Aaron Newton, but I want to show you what I came up with after a few days of jQuery AJAX chat and a few hours of MooTools AJAX chat…

One of the most important questions you can ask, when developing something that is going to do a lot of data transfer (very quickly), is what data/information format you are going to use. As I see it; there are 3 widely available options when working with Javascript: CSV, XML and JSON. CSV is a simple format but what do you use as column/row delimiters? What if the data includes tabs or new lines? Bummer! Next up is XML. XML is horrible. Next up is JSON; this is probably the most widely used data format in Javascript. It’s concise and simple to do with both Javascript/PHP.

There are problems with JSON though – it requires a third-party library to parse it (from string to object, PHP -> Javascript) in Javascript, or eval (evil). It also requires a third-party library in PHP to parse from/to JSON. So it’s a good format, but there are problems.

It is possible to use characters that users can’t input (control characters) – which are similar to \t and \n – to delimit CSV data. You can also do this in PHP and the only methods required in both Javascript/PHP are string split/join.

From → Javascript

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS