dan's ajax library

myIO

The new AJAX 'library' you already know how to use!

defaults: (all 'arguments' are optional)
arg default description
url location.href url to load/save
verb GET for using POST, HEAD, etc. not needed for PUT or GET
type "text/html" sets request format mime type. over-ride if using XML or POST.
data null for PUT and POST, the raw data to be sent to the server.
cachedOK false allow caching? (vastly speeds loading for files you don't expect to change)
good null success callback -argument passed is data, this is the XHR object
bad null failure callback - this is the XHR object
done null completion callback -argument passed is data, this is the XHR object



standard names / locations of arguments in other javascript libraries
Library: url good bad method
(get/put/post/etc)
async data
jQuery url callback error typeString async dataObject
prototype arguments[0] onSuccess onFailure method asynchronous parameters
moo tools url success failure method async data
YUI arguments[1] success failure arguments[0] NA argument(Obj)
myIO (native) url good bad method async data
All of the above keywords/interfaces work with myIO.
This means that you can use callback, success, good, and onSuccess interchangeably.
The arguments names/keywords are not case-sensitive and for all events the "on" prefix is optional.


Usage

There is no standard usage. Use as you would like an ajax function to perform.
Check out the examples and tests for inspiration. To test in your browser head over to the myIO ajax test page


Examples

alerts the source of the file test.txt (simple sync mode)

alerts the source of the file test.txt (sync mode)

alerts the source of the file test.txt (async callback)

requests the current page's source, and alerts the request's staus
(note how "this" refers to the appropriate xmlHttpRequest object)


writing: (if write permissions are available)
saves content in 2nd argument (string or string variable) to file "data.txt". myIO("data.txt", "hello world"); //disabled for the demo and on this server after running, "data.txt" will contain "hello world"...
default is background save; setting "asynch" to false will force a browser stall until save is complete.

show the value of a tag in the XML document test.xml


requests an XML doc ( test.xml ) , and alerts the raw response (should be an object of some type)


alerts the date of the last update of the file mini.txt
note that while the callback would work without specifying mode:"HEAD", doing so would waste bandwidth.
specifying mode:"HEAD" gets the headers without downloading the file contents, often in a single packet.
in this example, the returned string is parsed into a Date object and formatted using Date.toDateString()


fills the example box, id="example", with the contents of mini.txt


perform a YUI-style GET request of contents of mini.txt


Demonstrates the dual role of the first callback argument.
it works as a string for response text, document for responseXML.
In short, this allows you to write code for it either way.

Demonstrates basic usage of all three call backs


be sure to check out the library and browser test page for many more usage examples,
and a live compatibility check.



Include

basic usage: Include( url, target );
arguments: url: String: location of resource to include in the document.
target: (Element or String id of element): where to put the content of the resource
   Note:target is ignored for invisible content like CSS and scripts

Include Examples (double-click code to run)



loads the contents of a text file into the div below (id="example2"):


Example Div2
double click above example box to load me!


add an external stylesheet (test.css ) to the document
the background color of the page changes if it works.


loads the contents of a text file into the display textarea (id="example3"):


add an external script/jsonp data source(hello.js ) to the document
an alert box should appear if it works.


change an (image ) url
This can be useful to speed the loading of your page.
The onload event normally waits until all images are fully loaded before firing.
By omitting .src attribs on your images, you can reduce the amount of time it takes before onload fires.
You then apply Include to the images in an onload event, and they load after your script processes.
   waiting for image...




documentation © 2009, by DanDavis. All rights reserved.
The ajax library (io.js + ioc.js) is distributed under a creative commons attribution license