An uber lightweight library for building buzzword-compliant beta Web 5.0 applications.
- Download and stick the contents of pkg/ in your app’s javascript directory (the files in src/ contain comments and a bit of whitespace, whereas pkg/ contains minified versions).
- Depending on your needs, add one or more
<script>
tags, e.g.<script type="text/javascript" src="/js/ajax.js"></script>
, to your html.
mini.form.serialize(f)
Serializes all the fields in a form so that they can be passed as a query string in the form “arg1=val1&arg2=val2”.
mini.ajax.x()
The XMLHttpRequest object (or MS equivalent) used for communication
mini.ajax.send(u,f,m,a)
Send a basic Ajax request.
mini.ajax.get(url,func)
Uses a GET request to query the specified url and return a response to the specified function.
mini.ajax.gets(url)
Uses a GET request to query the specified url and return a response synchronously. Use this sparingly, as synchronous calls can lock up the browser.
mini.ajax.post(url,func,args)
Uses a POST request to query the specified url and return a response to the specified function.
mini.ajax.update(url,elm,method,args)
Uses a POST request to query the specified url and insert the result into the specified element.
- method = GET or POST (default)
- args = arguments as string (not used if specifying GET — instead pass args with url like this: “url?arg=val”)
mini.ajax.submit(url,frm,elm)
Used in the onsubmit handler of a function. The form is not submitted the usual way; the form is instead serialized using “ajax.serialize” and submitted using “ajax.post”. The result is then inserted into the specified element.
- frm = form element
- elm (optional) = element to update with returned content; if blank, returned content will be assumed to be javascript, and will be evaluated
Example:<form action="fallback/url" onsubmit="mini.ajax.submit('ajax/form/url', this, 'div_to_update');return false;">
mini.form.validate(frm)
Use in the onsubmit handler of your form to validate that required fields are completed, e.g. <form onsubmit="return mini.form.validate(this)">
Indicate required fields with class=“required”
Add label.error { color: red; }
or similar to your stylesheet so that errored fields will stand out.