Feeds

Xajax and PHP: JavaScript without the pain

Automatic for the people

  • alert
  • submit to reddit

Gartner critical capabilities for enterprise endpoint backup

Send an Ajax request

We shall create an Xajax application to validate an input field in a form. The input form takes data to add a catalog entry to the database table Catalog. As a user begins to enter data in the input field Catalog Id, a XMLHttpRequest is sent to the server to validate the Catalog Id value added.

If the Catalog Id is not already defined in the database, a message "Catalog Id is Valid" gets displayed. If the Catalog Id is already defined in the database, a message "Catalog Id is not Valid" gets displayed, the Create Catalog button gets disabled and field values for the Catalog Id get added to the form.

The xajax PHP object performs the function of an intermediary between the client application and the server. In the Xajax application PHP script create a xajax object.

$xajax = new xajax();

The server side processing is performed by PHP functions. Create PHP functions validateCatalogId($formValues) and updateCatalog($formValues). Both these functions take a formValues parameter.

function validateCatalogId($formValues){}
function updateCatalog($formValues){}

Register the PHP functions with the xajax object using the registerFunction() method. The xajax object creates wrapper functions for the PHP functions that may be invoked from a PHP script or an input form event handler.

$xajax->registerFunction("validateCatalogId");
$xajax->registerFunction("updateCatalog");

Xajax generates asynchronous wrapper functions for the registered PHP functions. A wrapper function name uses the format phpfunction. Variable phpfunction is a server-side PHP function for which a wrapper function is to be defined. Xajax provides asynchronous form processing with the getFormValues(string formId) method. Using the getFormValues() method, an array of form field values may be submitted as an argument to a xajax asynchronous function.

Sections of a form may also be submitted instead of the complete form with the getFormValues(string formID ,boolean submitDisabledElements, string prefix]) function. The prefix parameter specifies that only form elements starting with that prefix should be submitted. Boolean parameter submitDisabledElementsspecifies if disabled elements are to be submitted. PHP functions validateCatalogId and updateCatalog define a parameter for an array of form field values. Before a XMLHttpRequestis initiated, specify the xajax object to handle requests with the processRequests() function.

$xajax->processRequests();

Secure remote control for conventional and virtual desktops

More from The Register

next story
Why has the web gone to hell? Market chaos and HUMAN NATURE
Tim Berners-Lee isn't happy, but we should be
Mozilla's 'Tiles' ads debut in new Firefox nightlies
You can try turning them off and on again
Microsoft boots 1,500 dodgy apps from the Windows Store
DEVELOPERS! DEVELOPERS! DEVELOPERS! Naughty, misleading developers!
'Stop dissing Google or quit': OK, I quit, says Code Club co-founder
And now a message from our sponsors: 'STFU or else'
Apple promises to lift Curse of the Drained iPhone 5 Battery
Have you tried turning it off and...? Never mind, here's a replacement
Uber, Lyft and cutting corners: The true face of the Sharing Economy
Casual labour and tired ideas = not really web-tastic
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
prev story

Whitepapers

Gartner critical capabilities for enterprise endpoint backup
Learn why inSync received the highest overall rating from Druva and is the top choice for the mobile workforce.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Rethinking backup and recovery in the modern data center
Combining intelligence, operational analytics, and automation to enable efficient, data-driven IT organizations using the HP ABR approach.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
Next gen security for virtualised datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.