jQuery: AJAX contact form

This video tutorial by Remy Sharp (the Remy Sharp) shows how to implement a simple contact form with AJAX and jQuery. The implementation is pretty simple because the server response is atomic. However, when such a response involves the use of more messages, it becomes pretty complicated to handle them.

I fixed this problem by associating to every message the ID of the corresponding form field. So when I parsed the response with jQuery, I simply had to use such ID to append the HTML snippet to the corresponding field marked with that ID:

<div class="message" rel="ID" />

PHP returned simple HTML, so it was pretty easy to get the value of the rel attribute by treating the returned XMLHttpRequest object as an HTML DOM structure instead as a string.

Leave a Reply

Note: Only a member of this blog may post a comment.