Feeds

Xajax and PHP: JavaScript without the pain

Automatic for the people

  • alert
  • submit to reddit

New hybrid storage solutions

If the result set is empty display a message, "Catalog Id is Valid". The addAssign method sets the innerHTML of the validationMessage div.

$objResponse->addAssign("validationMessage","innerHTML","Catalog Id is Valid");

If the result has rows, set the innerHTML of the validationMessage div to "Catalog Id is not Valid".

$objResponse->addAssign("validationMessage","innerHTML","Catalog Id is not Valid");

Next, fetch values from the result set and set the values in the input form fields. Set the value attribute of the input form field elements with addAssign method. For example, the value attribute of the journal element is set as shown below.

$objResponse->addAssign("journal","value",$journal);

Also disable the submit button.

$objResponse->addAssign("submitForm","disabled",true);

Return the $objResponse object from the validateCatalogId function as an XML string.

return $objResponse->getXML();

Process the Ajax response

The XML response is sent to the xajax processor, which sends the XML response to the xajax’s JavaScript message pump. The message pump parses the XML instructions and sets the elements in the input page.

The data specified in the $xmlResponse object with addAssign; method is therefore set in the input form. The input.php script is available in resources zip.

Run the input.php script in the Apache web server with the URL http://localhost/input.php. Start adding a value for the Catalog Id field. An XMLHttpRequest request is sent to the server with each addition to the text field. The input page gets updated with response from the server that contains instructions about the validity of the Catalog Id. A message is displayed (below) to verify if the Catalog Id field value is valid.

Validating Input Field.

If a value is specified that is already defined in the Catalog table, a message "Catalog Id is not Valid" is displayed - as in our next screen shot.

Catalog Id not Valid.

A new catalog entry can be created by specifying a Catalog Id field that is valid and adding values to the other form fields, as shown in our final screen shot.

Catalog Id Valid.

Finally

Ajax has various applications such as auto completion, dynamic form validation, and partial page refreshes. In this article you have learned to use Ajax with PHP with a PHP framework for Ajax. You did not have to use an XMLHttpRequest object to open and send an Ajax request and process the Ajax response. Xajax generates the required JavaScript, thus, facilitating the development of an Ajax/PHP application. ®

Security for virtualized datacentres

More from The Register

next story
Not appy with your Chromebook? Well now it can run Android apps
Google offers beta of tricky OS-inside-OS tech
Greater dev access to iOS 8 will put us AT RISK from HACKERS
Knocking holes in Apple's walled garden could backfire, says securo-chap
NHS grows a NoSQL backbone and rips out its Oracle Spine
Open source? In the government? Ha ha! What, wait ...?
Google extends app refund window to two hours
You now have 120 minutes to finish that game instead of 15
Intel: Hey, enterprises, drop everything and DO HADOOP
Big Data analytics projected to run on more servers than any other app
New 'Cosmos' browser surfs the net by TXT alone
No data plan? No WiFi? No worries ... except sluggish download speed
prev story

Whitepapers

Providing a secure and efficient Helpdesk
A single remote control platform for user support is be key to providing an efficient helpdesk. Retain full control over the way in which screen and keystroke data is transmitted.
Top 5 reasons to deploy VMware with Tegile
Data demand and the rise of virtualization is challenging IT teams to deliver storage performance, scalability and capacity that can keep up, while maximizing efficiency.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.
Secure remote control for conventional and virtual desktops
Balancing user privacy and privileged access, in accordance with compliance frameworks and legislation. Evaluating any potential remote control choice.