Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
Getting StartedHelpful ResourcesAsk questions on the Help ForumRead the User GuideBrowse the Reference DocumentationSubscribe to the Helix Mailing ListLearning HelixAdvanced Topics

AJAX Support

You can use AJAX in your application without writing a single line of Javascript.  There is a global function named ajax() that will write the Javascript into your page.  Combined with the idea of codebehind files, AJAX support in your application only requires that you specify the name of a codebehind function and an HTML element to display the server response.

See the code below for an example of how you can set a codebehind function on the server to handle the click of a button in the browser:

// This code would appear in the markup file for the page

    // Make a new button
$button = new button("Click Me");
// Set the "onlick" attribute of the button to an AJAX call
$button->onclick ajax("some_codebehind_function","response_element");
// Display the button
echo $button;
// Display the div element to hold the response
"Response will appear here";
// This code would appear in the codebehind file for the page

    // Define the function that will be called when the button is clicked
function some_codebehind_function()
"This text is from the server at: " timestamp();

How Does It Work?

Helix will write the javascript code necessary to make a request to the server that is formatted to call the codebehind function named in the ajax() method.  The codebehind method that is called can either echo a response and/or return a response to the browser, and it will be inserted in the HTML document at the element named in the ajax() method.

See the ajax() method for a full list of parameters and options.

Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads