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.
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
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.
Include( url, target );
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"):
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.