Wednesday, July 30, 2014

AJAX: Asynchronous JavaScript and XML Tutorial 

What is AJAX?

AJAX Stands for Asynchronous JavaScript and XML is language used for making interactive web application. It is used at client side to make asynchronous web application.

AJAX allows client to interact server asynchronous (client request processed in background) so due to this it make web application faster and save bandwidth which required to reload the whole page and time.


AJAX is used to exchanging the data with server and updating the part of the page without reloading the whole page. AJAX is a technique of creating fast and dynamic web page.

Example of AJAX: The some sites like Gmail, facebook and Google extensively use ajax to save the bandwidth.

AJAX code lies in html and javascript. So no need to write separate file for ajax code. In AJAX, XML is used to exchange the data over server. 

Classic websites which do not use ajax need to reload whole page if some content of the page changes.

The flow of AJAX application is as follow:

Step 1:
At Browser Side :  when event occurs browser creates an XMLHttpRequest object and then it send and HttpRequest to the server

Step 2:
At Server Side : Server processes the HttpRequest and create the response and send it back to the browser

Step 3:
At Browser Side : Browser receive the response and process it back using javascript and then it update the page content.

AJAX Example :
    This is sample AJAX example. In this, when we press button named change content then the content of myDiv div changes without refreshing the whole page.

Let AJAX change this text

Now we will see what the above code of ajax says:

In the above code we have written our ajax code within java script and html code. In html we have taken one button with label "change content". We click this button the function from java script get called and  that function runs the ajax code.

In this ajax code, we first create the xmlhttp object to exchange the data over server asynchronously. To send data using xmlhttp we need to create first open the xmlhttp object using either GET method or POST method as a parameter to open() method and after that send the request using send() method.

we create the xmlhttp object as below

code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();

code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

and after that we open and send xmlhttp object as below"GET","ajax_info.txt",true);

In above open method, the first parameter is method i.e. get or post and second parameter is file or url of the server and third parameter is true or false. True means sent xmlhttp request asynchronously and false means sent xmlhttp request synchronously.

After getting xmlhttp request to the server it processes the request and sent back response. So client check the xmlhttp.readyState==4 and xmlhttp.status==200 if both are true then the client gets the response from the server. So client gets the response text from server using xmlhttp.responseText and then it changes myDiv content with response text.

So in this way using ajax the client changes the part of the page content without refreshing the whole page. Please make the comment on this tutorial so i will be back next time with some good one. Thanks for reading this.

Read More

Sunday, January 5, 2014

PHP MySQL Database tutorial

PHP MySQL Database tutorial :

What is PHP?

PHP is most popular server side scripting language used for web development. To know more about php and how to start with PHP programming CLICK HERE
PHP works with many databases. You can connect to many databases and manipulate with them with PHP. But the MySQL is most widely and popular databases with PHP. So now we learn more about MySQL.

What is MySQL?

MySQL is the widely used open-source Relational Database Management System(RDBMS). MySQL is the database used on the web and it is runs on the server side. MySQL is good for both small and large application. MySQL is reliable and easy to use database. MySQL is supported by number of platforms and It supports standard SQL.

So from this we got to know about both PHP and MySQL. So now we move to the PHP with MySQL that is how to use PHP with MySQL.

You can simply install PHP and MySQL on your PC with the help of complete package of XAMPP. XAMPP is acronym of  xml apache mysql php and perl. To know about how to install XAMPP on your windows machine please CLICK HERE

PHP MySQL Tutorial Content:

1) MySQL Connect Syntax :

First you have to connect to your mysql through PHP so you need to use mysql_connect().

Basic syntax for mysql connect is as below

mysql_connect(host name, username, password);
// Here host name is the name of host or ip address of host where mysql is installed

Try out the below code for mysql_connect()

//the example of MySQL database connection 

$conn = mysql_connect("localhost","","");
// write your mysql username and password in the second and third parameter of mysql_connect respectively
if ($conn) {
 echo ("Connection is succeed")
} else {
 echo ("Connection is fail")

2) MySQL Create database :
MySQL create database syntax is as below


3) MySQL execute Query :
Mysql execute query syntax is as below

Sorder="insert into table (val11,val2)";
mysql_query($order) ;
//The above command execute the insert sql command

4) MySQL fetch record :
The syntax of fetch single row or record from table is as below

$result=mysql_query("select id,name from student where id =10");



  echo "No record exist";




   $row= mysql_fetch_row($result);


echo $row[0];   //10

echo $row[1];   // suresh
Read More