Monday, April 4, 2011

Ajax PHP Basics

Ajax PHP Example

In this article I do not want to show you the history of AJAX and discuss its pros and cons, but only focus on how to create a basic working AJAX - PHP communication.

The only important thing at the moment is that AJAX uses JavaScript so it need to be enabled in your browser to successfully complete this tutorial.

To demonstrate the AJAX PHP connection we will create a very simple form with 2 input fields. In the first field you can type any text and we will send this text to our PHP script which will convert it to uppercase and sends it back to us.

So let's list what we need to do:

* Listen on key-press event on the input field.
* In case of key-press send a message to the PHP script on the server.
* Process the input with PHP and send back the result.
* Capture the returning data and display it.

PHP is a highly powerful programming language that can be used for web development as well as native applications. Data intensive online sites such as forums are heavily used with PHP as the programming language can easily handle the massive data changes online.
Sponsored Links


One of the most popular functionalities provided by PHP is the web form. These are fields wherein user data is required before access to any type of information is allowed. Through PHP, the needed information for online access can be extracted and the data can be used for other functions online.

But even with the power of PHP in developing web forms, it's still not as interactive compared to other online web forms. Users still have to click on submit and wait for the next page or page refresh just to know if the fields entered are correct. This setting can be quite frustrating if the web form is very long.

This is where the magic of Ajax can be used. With the help of Ajax functions, users will be able to learn more about the data entered in nearly real-time basis. This cuts down the need to refresh before verifying any data.

The key to this functionality in Ajax is the available functions to check on the data as they are entered. Certain functions can be added to PHP web forms so that the information can be verified without refreshing the information. These functions are not called when the user clicks on "submit" but the function is called as soon as the information is available.

Validation through Available Functions

There are many developers who can easily provide real-time validation process in the web forms. But there are too many libraries for Ajax and JavaScript functions that building an application can be very easy. Instead of developing a new function, developers can simply check into various libraries and frameworks for the needed function.

In this case, the best Ajax function that can support the web form on PHP comes from Prototype framework. There are other frameworks that have the real time validation but Prototype offers an easy to understand function.

Prototype uses "AjaxValidates.php" so that it will enable real time validation of the data entered. Of course, the source "prototype.js" has to be called so that the validation function created specifically for PHP can be used.

Connecting the Ajax Function to PHP Web Form

While the Ajax function that validates the data entered in real time is important, it will never exist without an efficient PHP web form. Developers have to successfully create a PHP web form so that the Ajax function should be able to interpret the entered data.

At first glance, the PHP web form developed for Ajax is almost the same. But since the function provided by Ajax validates in real time, the functions are added after each field. Users can simply transfer to another field in the web form while Ajax processes the data on the previous field and return with the prompt in case the data entered cannot be accepted.

10 comments:

  1. Acesoftech is a leading PHP training center which provides best training in Kolkata and Surat. The company provides training in such a way that its easy to learn and complete job oriented. We provide live PHP training.
    http://www.training.acesoftech.com/

    ReplyDelete
  2. Our web design company definitely makes it a use of php programming with the tough projects handling.The basics rule the programming though u r perfect with the project u make.

    ReplyDelete
  3. Acesoftech is No.1 PHP training center in kolkata. Our professional trainer can provide you PHP training in such a way that it will be complete job

    oriented. So, if you are looking for professional PHP

    training in Kolkata
    , acesoftech
    is the best choice for you.

    ReplyDelete
  4. Very informative blog,thanks for providing such information, i am looking for that one.

    ReplyDelete
  5. Really nice blog i like it ..This blog has very informative information for those students who want to join IT training .
    Thanks for sharing.
    PHP Training Classes

    ReplyDelete
  6. Awesome. just awesome...i haven't any word to appreciate this post.....Really i am impressed from this post....the person who create this post he is a great human..thanks for shared this with us.i found this informative and interesting blog. Pls drop by my buy tanning bed bulbs review site.
    PHP Traning

    ReplyDelete
  7. The world of tagging and coding in designing a site is my passion,if you feel the same then the course of PHP training can be really valuable for you to project your job with more perfection. it is amazingly good with working the open source.

    ReplyDelete
  8. The information you given here,it has worked wonderfull out here. This basics of information would do better for me to build a foundation.

    ReplyDelete
  9. I got so many points about PHP with Ajax from here and recently I am also working on it that's why i love reading your post. Thank you so much to share this post!

    ReplyDelete
  10. This is very good & useful blog i am regular follower thanks for posting wonderful article
    Thanks for providing such information.More details about php basic training visit karmickinstitute.com.

    ReplyDelete