
In this part, we will start you off with some very simple code just to show you how things get started. At the end of this tutorial you will have made your own 'hello world' AJAX script... (not a big deal I know, but you have to start somewhere!). I'll keep these tutorials bitesize and introduce a new command or concept on each tutorial to add to what has already been covered. Today, we start at the beginning with something that will be in all future scripts...
The what? ![]()
The XMLHttpRequest object is at the heart of AJAX. It allows you to send and receive data with javascript without refreshing the page and works on all browsers (except, you guessed it! Internet Explorer). All you have to do is find out if the browser supports it with an 'if' statement in the javascript contained in the <head> part of the html page and then create a XMLHttpRequest object using the 'new' command;
That would create a XMLHttpRequest object and store it in XMLHttpRequestObject.
But, what about Internet Explorer?.. We can't use XMLHttpRequest so we have to use an ActiveXObject. For us to do anything with an XMLHttpRequest and make sure it works on both IE and Firefox, we can add this to the javascript so we now have..
OK, that should cover us for making a XMLHttpRequest object, we can't do anything in this tutorial series without it so to be sure, lets just create the whole html document and test to see if it can make an object by adding another 'if' statement to output some text to the screen if the object creation was successful using the javascript command 'document.write()'.
You can click on the title of the code snippet above and see the plain text version, just copy this to your own file and save it as an HTML document or right click here and save it and test it. If it's working, it will display the message "hello world! I created an object!" in big letters.
YEY! we created a 'hello world' AJAX program!, I know it's not much use yet but this is the foundation for all future tutorials so even thought it's not that 'sexy' , it IS important to make sure we can create the object that will handle the data being sent to and received from a remote file.
We can get into the sexy ins and outs of using this on the next tutorial. Please come back again to see how we can use this to open a remote file and display it's contents on a HTML page without a reload...(ooh, I can't wait....)
![]()
Popularity: 6% [?]
The second part came in 13 days… I had to read back the first part to get in sync.. anyhow revision always helps…
I don’t remember the Enable CommentLuv checkbox below the submit button. Is it so that earlier the page was fetched on server end and latest version uses client to do so.
jalaj’s last blog post..Int() and Val() in JavaScript
i am giving CommentLuv a test for a few days on here before I release the new version. The checkbox was requested by someone who didn’t always want their comment to have a last blog post. Plus, it’s better to give people the choice. Also, I have added another routine that should make it more compatible with hosting that doesn’t allow CURL commands. I’ll post about it this week…
thanks for visiting!
Collect it in my binder done. Now, I can say hello to Ajax.
Still waiting for next lesson, guru.
thanks for visiting Agen, I hope you get some use out of these tutorials..
Hi, Andy, did you see yourself on my blogroll?
You’ve been an amazing resource for my php neediness.
I’m a leeetle nervous about implementing the final code, but it isn’t anything that a Ctrl-z wouldn’t cure anyway.
Thanks again.
witchypoo’s last blog post..Working with the police, part one
you should be able to run the code on your own PC, no need to upload it anywhere!
Yes a part two! I’m printing this and will be perusing it while I’m in the sauna this morning.
Opal Tribble’s last blog post..Guest Posting & Exercise From a Vegan Perspective
The next 2 parts will definitely be on time, I have them both saved as drafts ready to publish, they’re still not ‘look-at-what-a-cool-ajax-script-I-wrote’ yet but I think it’s important to get the beginning stuff done a little bit at a time.. by part 6 you’ll be able to put a useful script on a page and call it your own..
I have to use two ajax functions in an asp page not in asp.net, how i hve to create and use it
It allows you to send and receive data with javascript without
refreshing the page and works on all browsers
(except, you guessed it! Internet Explorer)
Huh? The XMLHttpRequest was written by Microsoft… why wouldn’t it work in IE?
it was however, originally developed by Microsoft as part of Outlook Web Access 2000, as a server side API call but Mozilla incorporated the first compatible native implementation of XMLHttpRequest in Mozilla 1.0 , IE needs to use activex to achieve the same functionality, IE also has issues with caching dynamic pages so even though it was originally written by microsoft, they don’t use it well in IE (coz it’s crap)
happy now?