MAY
26

Prototype js Quick Ajax Primer

technology — mike @ 11:46 am

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:
  1. function superButtonClick() {
  2. new Ajax.Updater('id_of_the_element','/backend_page.php', {
  3.   method: 'get',
  4.   parameters: {the_variable_name: 'the_variable_value'}
  5.  
  6. });
  7. }

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.

« Previous Page