I have a very dynamic site that uses this technology everywhere. We use Dojo, but the principles are the same. Like the above posters, your form should have onsubmit = "return false"; as an attribute (or as an object that it represents), so that the page does not reload.
On the server side, we do not use redirection, but respond using JSON (or XML or something else) and pass the response handler (jQuery, Dojo, etc.) what to do next.
In most cases, the process:
- Submit a form calling xhrPOST
- Work on the server
- Return JSON / xml / text
- Refer to this return value and determine what to do javascript
A specific example looks something like this:
- The user sends vitality to the patient
- The server checks and returns {success: "Received Vitals".} Or {error: "Invalid number"}
- The javascript xhr callback handler determines what to do next (closing the dialog box, updating the form for a new record, or drawing attention to the missing field)
Edit: Link to some Python web frameworks: link
Link to the basic tutorial on returning JSON in Django (with jQuery) link
One more note: when you use JSON, this is technically no longer AJAX, since X stands for XML.
Nicholas orlowski
source share