Calling with Ajax

 

Javajax comes with a javascript file to handle Ajax calls, error reporting and error fields highlighting.
The javascript Object AjaxCaller is a wrapper for Ajax.request object in prototype.js framework.
Please refer to prototype.js for parameters syntax specification.

AjaxCaller object requires 3 parameters: 

  • a form element, that can be the submit button or any other element in the form, or the form itself
  • the Ajax.request parameters
  • The action URL


  • The following code would call the example method: 

    function callMyMethod(formElement){  
    var url = "MyAction.myMethod.ajax";
    var ajaxParameters = {};
    var formParameters = {};

    var caller = new AjaxCaller(formElement, ajaxParameters);

    caller.send(url, formParameters);
    }


    The parameter formParameters is the content we want to post to the action; if it is not passed, the form itself is posted instead. 

    Here is a little more complete example:

    var callmeOnSuccess = function(transport) {

    alert(transport.responseText); }

    var callMyMethod = function(formElement) { var url = "MyAction.myMethod.ajax";
    var ajaxParameters = {onSuccess:callmeOnSuccess};
    var formParameters = {name:"Albert",surname:"Einstein"};
    var caller = new AjaxCaller(formElement, ajaxParameters);
    caller.send(url, formParameters);
    // or caller.send(url); if we want to post the form
    }

     

    Support JavAjax

    JavAjax is a free to use software, so you will never be asked for money to download and use it.
    However, if you find it useful, you may consider to make a donation to let the work go on!


    Support This Project

     

    (You will be redirected to the donation page. Donation is done through Paypal)