Home | Projects | Tutorials | Articles | live chat | Submit Project | Big Vote
 
Ajax Projects
.NET Frameworks
Java Frameworks
PHP Frameworks
Ruby Frameworks
Other Frameworks
Cool AJAX sites
Ajax Resources
Ajax Tools
JavaScript frameworks
Partners

 Home /  Tutorials / Ajax Beginners Tutorial

Ajax Beginners Tutorial





A cross platform tutorial for beginners, it's useful if you don't know how to use Ajax technology, it's recommended to start with this tutorial...

Read The Full Tutorial.
































Using Ajax

Page update without refresh using Javascript, PHP and XML's XMLHTTPRequest object (also known as 'remote scripting')

In this tutorial we'll discuss the basic principles of remote scripting using Ajax, a combination of javascript and XML to allow web pages to be updated with new information from the server, without the user having to wait for a page refresh.  Ajax therefore allows us to build web applications with user interfaces rather more like those of desktop applications, providing a better experience for the user.  Ajax tools are becoming increasingly popular, and a list of ajax development projects is also given.

Here you'll find:

  • a brief tour of the important principles of Ajax
  • code examples of all important points
  • links to further Ajax and related resources

This tutorial covers subjects which require some degree of familiarity with Javascript and PHP.  Beginners may therefore find it a little hard going, but hopefully should still be able to grasp the principles and uses of Ajax, if not the details.  There are some demos and further links at the bottom of the article and elsewhere on these pages - feel free to explore..

What is it?
The standard and well-known method for user interaction with web-based applications involves the user entering information (e.g. filling out a form), submitting that information to the server, and awaiting a page refresh or redirect to return the response from the server.

This is at times frustrating for the user, besides being rather different to the 'desktop' style of user interface with which (s)he may be more familiar.

Ajax (Asynchronous Javascript And XML) is a technique (or, more correctly, a combination of techniques) for submitting server requests 'in the background' and returning information from the server to the user without the necessity of waiting for a page load.

Ajax is actually a combination of several technologies working together to provide this capability.

How does it work?
Instead of a user request being made of the server via, for example, a normal HTTP POST or GET request, such as would be made by submitting a form or clicking a hyperlink, an Ajax script makes a request of a server by using the Javascript XMLHTTPRequest object.

Although this object may be unfamiliar to many, in fact it behaves like a fairly ordinary javascript object.  As you may well know, when using a javascript image object we may dynamically change the URL of the image source without using a page refresh. XMLHTTPRequest retrieves information from the server in a similarly invisible manner.

How is it coded?
There are a few, relatively simple, steps to coding an Ajax application.  The description below is an attempt to describe the salient points without bogging down the new user in too many of the technicalities.

Firstly, we need to know how to create an XMLHTTPRequest object.  The process differs slightly depending on whether you are using Internet Explorer (5+) with ActiveX enabled, or a standards-compliant browser such as Mozilla Firefox.

With IE, the request looks like:

http = new ActiveXObject("Microsoft.XMLHTTP");

whereas in a standards-compliant browser we can instantiate the object directly:

http = new XMLHttpRequest();

There's an example of a short piece of code to create the object here, which clearly demonstrates the different approaches for the two different browser types, along with a browser detection routine.

Secondly, we need to write an event handler which will be called via some event on our user's page, and will handle sending our request for data to our server.

The event handler will use various methods of our XMLHTTPRequest object to:

  • make the request of the server
  • check when the server says that it has completed the request, and
  • deal with the information returned by the server

We can make our request of the server by using a GET method to an appropriate server-side script.  Here's an example event handler called updateData which assumes that we have created our XMLHTTPRequest object and called it http:

function updateData(param) {
  var myurl = [here I insert the URL to my server script];


  http.open("GET", myurl + "?id=" + escape(param), true);
  http.onreadystatechange = useHttpResponse;
  http.send(null);

}

 

Note that the function listens to the onreadystatechange property of the XMLHTTPRequest object and, each time this parameter changes, calls a further function useHttpResponse.

You will note also that, for the sake of clarity, I have said little about the server-side script which is called - essentially this can be any server routine which will generate the required output when called with the relevant URL and appended parameters, as in any other HTTP GET request.  For the sake of the example we are passing a variable named id with a value param passed as an argument to the updateData function.

Thirdly, then, we need to write a function useHttpResponse which will establish when the server has completed our request, and do something useful with the data it has returned:

function useHttpResponse() {
  if (http.readyState == 4
) {
    var textout = http.responseText;
    document.write.textout;
  }
}

Note here that our function checks for a readyState value of 4 - there are various numbered states describing the progress of such a request, but we are only interested in the value of 4, which indicates that the request is complete and we can use the returned data.

In this case, we have received our information as simple text via the responseText property of our XMLHTTPRequest object.  Information can, however, be returned as XML or as properties of a predefined javascript object, though this is perhaps beyond the scope of this tutorial.

Try out all the techniques described above in the Ajax Demonstration

Making Ajax Easy

There are quite a few toolkits springing up that package the Ajax calls into useable libraries.  For small projects, these may not be worth using due to the code overhead and learning curve involved, but for more complex Ajax projects you may find them useful.  You'll find some relevant links below and elsewhere on these pages - feel free to explore.

sdds Says:
Tue Feb 10, 2009 12:03 pm
fsdfsf
Says:
Sun Feb 15, 2009 11:34 pm
Says:
Mon Feb 16, 2009 9:08 am
Says:
Mon Feb 16, 2009 10:01 pm
Says:
Wed Feb 18, 2009 8:52 am
Says:
Wed Feb 18, 2009 11:20 am
Freelance Web Designer in Delhi Says:
Wed Feb 18, 2009 11:22 am
Thanks , for the Guide .
Says:
Thu Feb 19, 2009 8:29 am
hfjhjg Says:
Fri Feb 20, 2009 1:41 pm
6464
dsfds Says:
Fri Feb 20, 2009 11:46 pm
dfg Says:
Tue Feb 24, 2009 11:40 am
dfgd
lll Says:
Thu Feb 26, 2009 12:34 am
lll
Says:
Fri Feb 27, 2009 7:14 am
er Says:
Fri Feb 27, 2009 7:30 am
er
Jacob Karma Says:
Sun Mar 01, 2009 5:33 pm
Very nice introduction. The full article has a place in my bookmarks now.
Says:
Wed Mar 04, 2009 9:49 pm
Says:
Sat Mar 07, 2009 9:36 am
test Says:
Mon Mar 09, 2009 6:07 pm
test
Says:
Tue Mar 10, 2009 8:00 am
Says:
Tue Mar 10, 2009 6:28 pm
yurt Says:
Wed Mar 11, 2009 12:52 am
rgtzdgsf
test Says:
Thu Mar 12, 2009 10:16 am
test
Says:
Thu Mar 12, 2009 12:55 pm
Says:
Thu Mar 12, 2009 1:03 pm
test Says:
Sat Mar 14, 2009 5:12 pm
test
Says:
Sun Mar 15, 2009 12:37 pm
Says:
Mon Mar 16, 2009 8:17 pm
Says:
Tue Mar 17, 2009 6:13 am
Lima Says:
Tue Mar 17, 2009 6:07 pm
Line 1
Line 2
Line 3
Wes Says:
Sun Mar 22, 2009 1:26 am
wicked post man.
Website Design Says:
Wed Mar 25, 2009 1:48 am
Great guide. Thanks for the information. I am teaching a class on this information and this will be helpful for the beginners.
trtrtr Says:
Thu Mar 26, 2009 8:19 am
dgd
YO Says:
Tue Mar 31, 2009 8:21 am
Poeng Says:
Wed Apr 01, 2009 10:42 am
It is helping a lot.
Says:
Sat Apr 04, 2009 5:39 am
pra veen Says:
Mon Apr 06, 2009 1:15 pm
you must have to need some advance example like how to use radio button and checkbox and somthing new because this is common and avialable everywhere
Says:
Thu Apr 09, 2009 10:05 pm
Says:
Sat Apr 11, 2009 9:44 pm
Says:
Wed Apr 15, 2009 12:00 pm
Says:
Sat Apr 18, 2009 11:14 am
Says:
Sun Apr 19, 2009 3:46 pm
Says:
Thu Apr 23, 2009 5:42 am
Says:
Sat Apr 25, 2009 2:27 am
hj Says:
Thu Apr 30, 2009 2:56 am
hjhj
sad Says:
Sat May 02, 2009 8:54 am
vmdfg
rweywreyrwey Says:
Sat May 02, 2009 8:54 am
vmdfg
testman Says:
Thu May 07, 2009 2:24 pm
testmessage
dsflksad Says:
Thu May 07, 2009 2:35 pm
fucking ajax tutorials what can i know that it is ajax
dsflksad Says:
Thu May 07, 2009 2:35 pm
fucking ajax tutorials what can i know that it is ajax
Says:
Fri May 22, 2009 1:00 pm
Says:
Fri May 22, 2009 1:04 pm
sucking ajax tutorials
Says:
Sat May 23, 2009 7:41 am
00ps! Says:
Fri May 29, 2009 11:30 am
i wanna learn this Says:
Sat May 30, 2009 3:24 pm
i wanna make this happen
Javagenious Says:
Tue Jun 02, 2009 1:54 pm
Thanks
Jennifer Says:
Wed Jun 03, 2009 6:31 am
Its really useful...
Thanks for the help..
Says:
Wed Jun 03, 2009 6:40 pm
asw Says:
Sun Jun 07, 2009 11:01 am
Good Keep It Up
Says:
Sun Jun 07, 2009 1:16 pm
Says:
Tue Jun 09, 2009 2:00 am
karthic Says:
Tue Jun 09, 2009 12:22 pm
oops
Says:
Wed Jun 10, 2009 3:21 pm
rj Says:
Fri Jun 12, 2009 1:11 pm
it will be a good help for all the beginners like me.
asdf Says:
Sat Jun 13, 2009 4:55 am
;lfdsdl;jg;ldfjsg
fhg Says:
Sat Jun 13, 2009 10:00 pm
ghfhfhfg
fhg Says:
Sat Jun 13, 2009 10:08 pm
ghfhfhfg
123 Says:
Tue Jun 16, 2009 10:34 pm
123
Says:
Wed Jun 17, 2009 11:28 am
Says:
Wed Jun 17, 2009 11:07 pm
hi Says:
Fri Jun 19, 2009 4:29 am
rrreretrt
Says:
Sun Jun 21, 2009 10:08 am
asd Says:
Wed Jun 24, 2009 4:08 am
dasdasdasd
weqwq Says:
Thu Jun 25, 2009 5:58 am
qwe
james Says:
Thu Jun 25, 2009 6:05 am
asdsad
hi Says:
Thu Jun 25, 2009 6:06 am
lkasd
sdf Says:
Fri Jun 26, 2009 2:20 pm
asdf
oop Says:
Fri Jun 26, 2009 2:21 pm
working fine just testing..............................................
...........
shri Says:
Tue Jun 30, 2009 5:28 am
thanking you.........
df Says:
Fri Jul 03, 2009 8:16 am
f
Asshole MotherFucker Says:
Fri Jul 03, 2009 9:12 pm
what THE FCUK do you THINK's THIS !!?? lolx
Says:
Sat Jul 04, 2009 9:57 pm
gng Says:
Mon Jul 06, 2009 1:04 pm
vbnvbn
Says:
Mon Jul 06, 2009 1:05 pm
hfg Says:
Fri Jul 10, 2009 12:26 pm
hjkhjkhjkhjk
fgh Says:
Fri Jul 10, 2009 12:42 pm
rjujnvnfhjjkfhj
Website Designers Says:
Sun Jul 12, 2009 7:18 am
Very good informative site.
Miguel Says:
Sun Jul 12, 2009 2:31 pm
time 2 try it
Says:
Sun Jul 12, 2009 5:32 pm
Says:
Sun Jul 12, 2009 6:58 pm
Says:
Tue Jul 14, 2009 1:05 pm
asdfsa Says:
Wed Jul 15, 2009 8:24 am
asdfasfasdf
Says:
Wed Jul 15, 2009 9:33 am
8675309 Says:
Thu Jul 16, 2009 2:45 am
Testes!!!
Says:
Fri Jul 17, 2009 3:07 pm
feels good man
dssssssss Says:
Mon Jul 20, 2009 12:57 am
ssssssssssssssssssssss
dasdsa Says:
Tue Jul 21, 2009 3:01 am
dsadasddasdsa
zxc Says:
Tue Jul 21, 2009 5:40 am
zxc
Says:
Tue Jul 21, 2009 10:04 am
7th hokage Says:
Fri Jul 24, 2009 7:02 am
this is cool
Robert Smith Says:
Sun Jul 26, 2009 8:57 pm
Robert Smith Says:
Sun Jul 26, 2009 8:58 pm
very insightful
Says:
Tue Jul 28, 2009 6:10 pm
Says:
Sat Aug 01, 2009 2:12 am
342234234234234234 Says:
Sun Aug 09, 2009 6:23 am
234234234
12 Says:
Tue Aug 11, 2009 7:16 am
Says:
Mon Aug 17, 2009 7:15 am
Says:
Mon Aug 17, 2009 3:34 pm
teshan Says:
Thu Aug 20, 2009 10:37 am
asdasdasd
dgfd Says:
Fri Aug 21, 2009 12:52 pm
hd Says:
Sat Aug 22, 2009 10:24 pm
testing
Says:
Tue Aug 25, 2009 3:07 pm
Says:
Wed Aug 26, 2009 1:10 pm
blogtips Says:
Fri Aug 28, 2009 5:17 am
Thanks, looking for an introductory tutorial.
Says:
Thu Sep 03, 2009 10:59 am
a Says:
Thu Sep 03, 2009 5:30 pm
aasd
jaymo Says:
Fri Sep 04, 2009 11:09 am
good
death comes ripping Says:
Mon Sep 07, 2009 3:06 pm
testing

<b>does is like tags?</b>
vvvvv Says:
Mon Sep 07, 2009 8:32 pm
ffff
tryrtyryryrt Says:
Wed Sep 09, 2009 10:22 am
ererwerwer
Says:
Mon Sep 14, 2009 6:34 am
Says:
Mon Sep 14, 2009 3:43 pm
Says:
Tue Sep 15, 2009 4:40 am
Says:
Tue Sep 15, 2009 7:20 am
ewd Says:
Wed Sep 16, 2009 8:52 am
edwedw
ewd Says:
Wed Sep 16, 2009 8:53 am
edwedw
ewd Says:
Wed Sep 16, 2009 8:53 am
edwedw
Says:
Thu Sep 17, 2009 9:25 am
67657 Says:
Fri Sep 18, 2009 3:21 pm
yuytu
ttyy Says:
Sat Sep 19, 2009 4:21 am
Hello it works?
Try Says:
Thu Sep 24, 2009 12:24 pm
Yes..
test Says:
Fri Sep 25, 2009 6:48 pm
test
er Says:
Wed Sep 30, 2009 12:15 am
ewrewr
dfsd Says:
Thu Oct 01, 2009 4:19 am
sdfsdfdsf hey>
booboo Says:
Fri Oct 02, 2009 1:58 am
hola
tete Says:
Mon Oct 05, 2009 9:26 am
tetete
dfafsdf Says:
Tue Oct 06, 2009 6:27 am
fasfsf fa f
sdfsf Says:
Tue Oct 06, 2009 9:04 am
dfdsf
Says:
Thu Oct 08, 2009 5:03 am
wfcwefwf Says:
Thu Oct 08, 2009 9:11 am
testing
Says:
Thu Oct 08, 2009 11:42 am
sgsfgs Says:
Thu Oct 08, 2009 5:39 pm
dsfgfdsgsd
erer Says:
Mon Oct 12, 2009 8:58 am
sdfsdfsdfsdfsdf
Says:
Mon Oct 12, 2009 1:06 pm
Bob Says:
Tue Oct 13, 2009 5:38 pm
Ajax too the rescue
rtutu Says:
Wed Oct 14, 2009 8:05 am
tuutu
sadsjhdhj Says:
Wed Oct 14, 2009 10:31 am
sdjhdbhhjdjh
abhishek Says:
Fri Oct 16, 2009 1:52 pm
<a href="http://www.libmaker.com/">http://www.libmaker.com/</a>
Says:
Sat Oct 17, 2009 6:38 pm
Says:
Mon Oct 19, 2009 8:04 pm
a Says:
Sat Oct 24, 2009 10:19 pm
a
Desarrolos Says:
Sun Oct 25, 2009 4:20 am
Ajax is a wonderful tecnology.

And its very useful.

Thanks.
neon tabela Says:
Mon Oct 26, 2009 5:07 pm
Thanks for explaining the AJAX in details, i get lots of information about fundamentals of AJAX.



Says:
Wed Oct 28, 2009 11:13 am
eheheh Says:
Sat Oct 31, 2009 3:40 pm
eheheh
venkat Says:
Thu Nov 05, 2009 5:50 am
thank you for explaining the concept
aerospike Says:
Thu Nov 05, 2009 10:53 am
this tutorial is so complicated
aprino Says:
Mon Nov 09, 2009 12:50 pm
please send me the good tutorial of ajax
thanks b4
Superannuation Says:
Fri Nov 13, 2009 12:26 pm
Nice Post Admin..

If you are looking for Home Loan, Superannuation, Public Liability, Professional Indemnity, Personal Loans, Business Loan, Car Finance, Commercial Life Insurance quotes
visit: http://www.financialservicesonline.com.au/
Superannuation Says:
Fri Nov 13, 2009 12:30 pm
Nice Post Admin..

If you are looking for Home Loan, Superannuation, Public Liability, Professional Indemnity, Personal Loans, Business Loan, Car Finance, Commercial Life Insurance quotes
visit: http://www.financialservicesonline.com.au/
dcd Says:
Fri Nov 13, 2009 2:23 pm
sfdsfd
a Says:
Sun Nov 15, 2009 1:25 pm
d
rapidshare downloads Says:
Mon Nov 16, 2009 9:07 am
thanks!!!!
babu Says:
Mon Nov 16, 2009 12:02 pm
thank you for your details
Says:
Fri Nov 20, 2009 11:07 am
Says:
Thu Nov 26, 2009 6:49 pm
halı yıkama makinası Says:
Tue Dec 01, 2009 5:24 pm
Nice Post Admin
Dantel perde modelleri Says:
Tue Dec 01, 2009 11:39 pm
this tutorial is so complicated. thanks
Says:
Wed Dec 02, 2009 9:05 am
asdas
Says:
Sat Dec 05, 2009 5:45 am
push-E Says:
Mon Dec 07, 2009 5:49 am
nice
Balamurugan Says:
Wed Dec 09, 2009 5:06 am
thanks it is useful,i need more explanation
sda Says:
Wed Dec 09, 2009 11:55 am
hi
wqw Says:
Sun Dec 13, 2009 12:27 pm
pradeep Says:
Mon Dec 14, 2009 5:46 am
its fine somewhat..hav to give more explanation..
Says:
Thu Dec 17, 2009 6:34 pm
asasas Says:
Thu Dec 17, 2009 6:35 pm
fuck
Ed Keeman Says:
Fri Dec 18, 2009 1:41 pm
Huh?
web tasarým Says:
Mon Dec 21, 2009 11:55 am
thanks
Says:
Mon Dec 21, 2009 7:23 pm
helped me alot , thanks
Says:
Tue Dec 22, 2009 8:46 am
sd Says:
Tue Dec 22, 2009 11:38 am
sandalye Says:
Tue Dec 22, 2009 3:15 pm
thank site good nice post
izmir somine Says:
Tue Dec 22, 2009 3:16 pm
thank site
Says:
Wed Dec 23, 2009 5:22 am
great work and simple thaught
sjef Says:
Thu Dec 24, 2009 1:24 pm
Test
testing Says:
Fri Dec 25, 2009 4:16 pm
test
srisoft Says:
Sat Dec 26, 2009 5:03 am
This is simply superb.
Says:
Tue Dec 29, 2009 9:04 am
Says:
Tue Dec 29, 2009 11:30 am
sfsfsf Says:
Tue Dec 29, 2009 6:26 pm
bvjgvjv
Says:
Wed Dec 30, 2009 7:14 am
thanks
JavaGenious Says:
Thu Dec 31, 2009 7:48 am
Thanks
JavaGenious Says:
Thu Dec 31, 2009 7:48 am
Thanks
AjaxExpert Says:
Thu Dec 31, 2009 7:49 am
Thanks for the info
Jewelson Says:
Sat Jan 02, 2010 3:15 pm
How do we implement this to show comment like here ...? I mean what code do we use .. can we use this method?
myc1 Says:
Tue Jan 05, 2010 11:41 am
thanks
William Says:
Tue Jan 05, 2010 8:00 pm
Thanks so much, really useful!
som Says:
Wed Jan 06, 2010 11:35 am
gud one :)
Ýzmir Fireplaces Says:
Thu Jan 07, 2010 11:27 am
thanks informative site
ModelSomine Says:
Thu Jan 07, 2010 11:29 am
Thank effort was
samual Says:
Fri Jan 08, 2010 1:36 pm
this is not useful
jin Says:
Sun Jan 10, 2010 3:41 pm
ggggggg
hosting Says:
Mon Jan 11, 2010 2:13 pm
Great work dude, keep it up. I found it while looking for cheap web hosting data.
winner Says:
Tue Jan 12, 2010 5:12 am
It's nice.If more information provided with more examples it will be more useful than now.
vietanh Says:
Sat Jan 16, 2010 8:37 am
zxczxc Says:
Sun Jan 17, 2010 2:17 pm
xzczxzxc
zx
xzc
xzc
xzc
mobilya Says:
Mon Jan 18, 2010 11:53 pm
thank site good nice post
Says:
Tue Jan 19, 2010 12:06 pm
asdd Says:
Tue Jan 19, 2010 12:06 pm
asd
Says:
Thu Jan 21, 2010 6:50 pm
try
international business degree Says:
Sat Jan 23, 2010 7:22 am
A cross platform tutorial for beginners, it's useful if you don't know how to use Ajax technology, it's recommended to start with this tutorial...
accounting degree Says:
Sat Jan 23, 2010 7:22 am
RSS is a popular format for syndicating and displaying external content on your site, such as the latest headlines from CNN. Well, with this powerful RSS ticker script, you can now easily display any RSS content on your site in a ticker fashion! This scri
administration and supervision degree Says:
Sat Jan 23, 2010 7:23 am
Thanks for the post, had been Googling for a while over this!
information technology degree Says:
Sat Jan 23, 2010 7:23 am
Thanks for explaining the AJAX in details, i get lots of information about fundamentals of AJAX.
interior design degree Says:
Sat Jan 23, 2010 7:23 am
Requirement of this script: Ability to run PHP on your site. Note that page(s) displaying the ticker and the backend PHP script must be on the same domain due to Ajax limitations.
soorej Says:
Wed Jan 27, 2010 4:33 am
no comments
captain Says:
Tue Feb 02, 2010 6:07 am
Nice .Need to publish more tutorials for really useful to absolute programmers. awaiting for that
lol Says:
Thu Feb 04, 2010 3:03 pm
lol
SXCF Says:
Fri Feb 05, 2010 1:54 pm
AASDASDASD
dekorasyon Says:
Sat Feb 06, 2010 7:25 am
hank site good nice post...
wow guy Says:
Mon Feb 08, 2010 3:44 pm
wow wow
Says:
Tue Feb 09, 2010 12:55 pm
Says:
Tue Feb 09, 2010 1:19 pm

Leave Your Comment

Name (Required)
Mail (will not be published) (required)
Website
AddThis Social Bookmark Button
Top Projects
MSN Web Messenger
MessengerFX
ebuddy
e-messenger
ILoveIM
AJAX file upload
You Tube
KoolIM.com
Meebo
Ajax.NET Professional
Tutorials
3D-style animation in JavaScript
Bug with Ajax HTML Grid and File Upload Forms
Top Floating message box using jQuery
Simple AJAX chat in PHP
Using jQuery with ASP .NET
Using the Ajax control toolbox with jQuery (and ASP.NET MVC)
Html Form submit using Ajax
Handling Session timeout & other server http errors in AJAX
TohDoh Yet Another CakePHP AJAX Todo-List
Replace jQuery Validation Message Formatting with ASP.NET AJAX