introduction
Byteson is a lightweight low-level Ajaj library that can send or recieve simple or complex variables using the powerful JSON protocol.
Byteson converts automatically variables using internal JSON convertion algorithm, based on original json.js file
Byteson is a part of byte family and is optimized to be compressed with common JavaScript compressors then has a clean and simple source code.
It is compatible with most recent browsers and MemTronic compressed version size is less than 2Kb.
history
- 7 December 2006 little update, V 0.2b available with a new request options param called timeout to add a timeout for each request. Callbacks will accept a second or third argument too with request informazions to use easyly a single object to performe each request.
- 16 November 2006 byteson V 0.2 is available
credits
Matteo Galli (aka Ratatuia) for Safari debug.
examples
These links show only few byteson features but I'm working to add better or more complete examples. Please stay tuned :-)
- first byteson demo page simple JS/PHP interaction with client and server code W3 validator with DOM and byteson JSON request to PHP page that parses a SOAP response and returns them as JSON result
f.a.q.
- What does Ajaj mean ? Ajaj means Asynchronous JavaScript and JSON and is a fast, bandwidth safe and portable way to send or recieve JavaScript variables using JSON (JavaScript Object Notation) convertion. Ajaj is really a good Ajax alternative and is very simple to implement with every compatible server side language. To read more about JSON and its language compatibility list please visit this page: http://json.org/
- What is byteson browser compatibility list ? byteson has been successfully tested withe these broesers: Internet Explorer 5.5+, FireFox 1+, Opera 9+, Safari 2+ and Khtml 3.4+ . Safari and Khtml probably don't work with MemTronic compressor than please use byteson packed version if You need Safari compatibility.
- Why byteson is not compatible with IE5 too ? Because JSON decode regular expression, based on orginal json.js JavaScript file, is not compatible with IE5.
- What is byteson license ? byteson has a Mit style license. You can read more about Mit license inside byteson Open Source javasript file.
- What is byteson philosophy ? the same of bytefx
- Does byteson modify something ? byteson shouldn't modify any other script.
-
Does byteson logo exist ?
This is an anti pixel logo that You could show on your byteson based pages

P.S. I really don't know wich f.a.q. should be usefull then if you have some idea please contact me using this page.
api introduction
utf-8 and encoding informations
byteson converts automatically sent JSON string with encodeURIComponent function.
This function is the best to send unicode JS chars using utf-8 charset and every recent server-side language can manage or modifiy this kind of charset.
When your favourite server-side language recieves byteson post JSON string, it should deocode, if necessary, this one.
With php, for example, You could use utf8_decode function, just before JSON to PHP parsing (i.e. before json_decode or Pear $ServiceJSON->decode).
If You just use utf-8 as charset with your server-side you don't need to decode anything.
When You write a byteson dedicated response, than a JSON string, You should convert this one into utf-8 compatible string.
With PHP, for example, you could simply use utf8_encode over JSON encoded string (i.e. after json_encode or $ServiceJSON->encode)
Note that You don't need to use urlencode or rawurlencode functions but You could use that but you need to specify decode:true inside options generic object.
With this option, byteson will decode automatically recieved string with decodeURIComponent function, just one time and before JSON convertion.
byteson api
convert
This method is used by byteson.encode method but should be used to do these convertions too
- JSON string to Date object
- object to generic class
byteson.convert(params:* [, result:Instance]):* @param * String or Object @param Instance optional new generic class instance if first parameter is an object. @return * new Date or new Instance with object parameters.
Note: please read more about this special method inside byteson summary txt file (index number 4)
decode
Returns a JavaScript variable from a valid JSON encoded string or returns undefined.
Returned variable types
- null
- Array
- Boolean
- Number
- Object
- String
byteson.decode(params:String):* @param String valid JSON encoded string @return * converted variable or undefined is params is not a JSON compatible string.
Note: JSON Date is encoded as a string and returned value is decoded as a String too. You could convert this kind of string using byteson.convert to get original Date object
encode
Creates a valid JSON string rappresention of generic object.
Encoded variable types
- null
- Array
- Boolean
- Date
- Number
- Object
- String
byteson.encode(params:*):String @param * Array, Boolean, Date, Number, Object or String variable. @return String JSON genric object rappresentation or empty string if param is not compatible.
Note: doesn't accept undefined or unknown values
request
Creates and manage a JSON request, sending an encoded generic variable.
byteson.request(page:String [, params:* [, options:Object ]]):Boolean @param String valid server side url to call @param * every JSON compatible variable to send @param Object byteson dedicated generic options object. @return Boolean true if request is possible, false if browser doesn't support Ajaj.
Note 1: If You send params argument request will send JSON value using the POST method. You could get this JSON sent string using the "byteson" POST variable. This will be automatically encoded using encodeURIComponent function then You need to decode, if necessary, and then parse with your favourite JSON porting.
Note 2: Please read Generic Object options Informations inside byteson summary txt file (index number 5).
xhr
Creates an XMLHttpRequest object and returns them or null, if this is not available.
Parameters list
byteson.xhr(void):* @return * new XMLHttpRequest (Xml H R => xhr) or null if browser is not compatible.
byteson :: generic options informations
This is a generic byteson interaction schema example with options parameters sequence.
Interaction Schema
------------ | Parameters | ------------ async:Boolean asynchronous (true) or synchronous (false) interaction, true by default decode:Boolean uses decodeURIComponent before JSON to JS convertion timeout:Unsigned Integer (ms) uses timeout for the reuqest (calls error method, if present, with "timeout" String as first argument) pass:String optional password, null by default user:String optional user name, null by default -------------------- | Interaction Scheme | -------------------- options | ----- init ----- | | error send | ---- loading ---- | | error load init [readyState = 1] options.init(xhr, request) called before xhr.send(*) [xhr.open is just called] You can modify headers or everything else. send [readyState = 2] options.send(xhr, request) called when xhr has opened connection and is sending informations NOTE: Please remember that Opera browser, and maybe others, doesn't burn this event. loading [readystate = 3] options.loading(xhr, request) called when xhr is downloading the request. With some browser headers and responseText lenght are available, then You should implement a sort of preload. load [readyState = 4] options.load(*, xhr, request) [* is the JSON decoded variable or undefined] called on interaction complete if xhr.status is 200 or 304. error [readyState = 4] options.error(string, xhr, request) [string is 'Request failure\nStatus:' + xhr.status or string 'timeout'] called after init on request failure or called on intercation complete if status is different from 200 or 304. ---------------------- | The new request param | ---------------------- New request param is an object that contains request informations. It has 3 properties: page, params and options. These properties are the same used when byteson.request is called and should be useful to know wich request fails or is used expecially whhen You use the same function or the same options object to perform every request.
Note: You could read these informations inside byteson summary txt file.
download
These are versions 0.2b of byteson library.
- Memtronic version (2.02 Kb) the smallest one, compatible with Memtronic compressor compatible browsers.
- Packer version (3.16 Kb) an alternative compressor that's probably more compatible than Memtronic.
- Open Source version (8.97 Kb) byteson library source code with license and comments
This is an extra txt file with a simple byteson summary
- byteson portable summary (7.48 Kb) If you need a portable API with methods and params descriptions You could simply use this file