AJAX with Prototype

Get AJAX

The prototype library encapsulates AJAX in a cross-browser manner and adds new functionality with a custom Ajax object.

The second parameter is a simple javascript object created on the fly. It has a property named "method" with the value "get" and another property named "onComplete" with the value "showResponse". When the function is called, it creates a new platform-independent Ajax request which talks to the server using the get method. When the request is complete, it calls the showResponse() method, which manipulates and outputs the data.

code

function getAjax(){
  var myAjax = new Ajax.Request(
    "test.html",
    {
      method: 'get',
      onComplete: showResponse
    }
  );
} // end function

function showResponse(originalRequest){
  alert (originalRequest.responseText);
} // end function