Add to Favorites

Prototype js Quick Ajax Primer

For those budding developers out there looking to get into ajax, here is a short tutorial of an easy way to ease into it.
If you haven't yet looked into a javascript framework such as prototype, now is the time to do so.
Prototype gives a quick and easy way to do some simple ajax calls from your javascripts without doing a lot of work.

For example, if you wanted to submit a variable to a backend page, putting the result of the call into a html element.

[code]
function superButtonClick() {
new Ajax.Updater('id_of_the_element','/backend_page.php', {
method: 'get',
parameters: {the_variable_name: 'the_variable_value'}

});
}
[/code]

That simple snippet when called from a button onClick will fetch the results of url "backend_page.php?the_variable_name=the_variable_value" and place them into a html element with the id "id_of_the_element".

It's really that simple to make an ajax call using the prototype js framework.

Comments

Be the first to leave a comment on this post.

Leave a comment

To leave a comment, please log in / sign up