fcOnTheWeb Logo Web technologies, made easy.

fcOnTheWeb Red DotAn Introduction to AJAX

We got a request in through the system to address an introduction to AJAX and what it is all about. So that is what we are going to do.

AJAX, which stands for asynchronous JavaScript and XML, is nothing to be scared of. What it essentially is, is using JavaScript to load a page and getting a response from that page.

For example you might use JavaScript to submit a variable to a server page, and then get the response after the server page has worked with that variable. That is what we'll be doing today.

In our example, we will not be strictly using XML but the theory is the same. We will be submitting a variable to a PHP page, working with it on our PHP page, and returning it back to the original page.

You can see and try out the example for yourself below. Enter your name and click "Get name". Then watch the text magically appear below the form.

Now, let us look at how we do this.

First of all, we have a very simple form to enter the data.

<form name="ajax_form">

<input type="text" name="provided_name" maxlength="25" />

<input type="button" value="Get name" onclick="javascript:change_content();" />

</form>

The key element of our form is the button, with which the onclick event will call our JavaScript function. And it is in the JavaScript where the magic will happen.

function change_content() {

xmlHttp = GetXmlHttpObject();

var url = "./ajax_example_page.php?providedname=" + document.forms.ajax_form.provided_name.value;

xmlHttp.onreadystatechange = new_text_ready;

xmlHttp.open("GET", url, true);

xmlHttp.send(null);

}

function GetXmlHttpObject(handler) {

var objXMLHttp = null;

if (window.XMLHttpRequest ) {

objXMLHttp = new XMLHttpRequest ();

} else if (window.ActiveXObject) {

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

}

return objXMLHttp;

}

function new_text_ready() {

if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {

display_new_text(xmlHttp.responseText);

}

}

function display_new_text(new_text) {

document.getElementById("div_to_change").innerHTML = new_text;

}

Our change_content function first creates a new xmlHTTP object. We then use this object to access our server page which we defined in our url variable. We are passing in the text entered into the form field through the get string.

Before we make the call to the page however, we define what we want to happen when the call is completed and we set this as the new_text_ready function. (xmlHttp.onreadystatechange = new_text_ready;)

We then open the connection to the page and send the data through.

When the state changes, we check to see if it is the result which indicates the page has completed. If it is, we then call our change_content function to update our local page. We pass in the responseText which is the code sent by the page. We then use the simple DOM technique of updating the page.

To test that our processes are working on the page we are calling remotely, we can open that page in a separate window for testing purposes. Then we can see any errors that are being thrown, etc. To do this, add the following line after the xmlHTTP.send() command.

window.open(url, "tempWindow", "status=1, toolbar=0, width=760, height=520, resizable=1");

This will open the server page in a new window for you to see. The properties at the end are optional and merely style the window how you want - not necessary for our testing.

Our server, PHP page ajax_example_page.php looks like this:

echo "<p>The name you entered was: " . $_GET["providedname"] . ". AJAX is easy.</p>";

And there you have it. AJAX, in a nutshell. Obviously this is a very brief and basic introduction to the whole, deep scope of AJAX, but now you have got something to work with you can go forth and make great creations.

AJAX is a powerful technology and is currently being used all over the Internet. It is certainly something of a buzz word to drop into a conversation, along with Web 2.0... Great applications can be created with AJAX, and it brings that feeling of a desktop environment to your web application.

ferrari_chris

oakley sunglasses cheap (http://www.oakleysunglassescheap.us.com/) says:

2014-07-12 02:06:27

http://www.oakleysunglassescheap.us.com/ oakley sunglasses

cheap
http://www.coachoutletstoreonlineco.com/ coach factory outlet
http://www.abercrombie-andfitch.com/ abercrombie and fitch
http://www.michaelkors-outletsonline.com/ michael kors outlet
http://www.oakley-sunglassesoutlet.com/ oakley sunglasses

outlet
http://www.tory-burchoutlet.com/ tory burch outlet
http://www.abercrombieandfitchstore.com/ abercrombie & fitch
http://www.rayban--sunglasses.com/ ray ban sunglasses
http://www.fit-flops.co.uk/ fitflops
http://www.coachoutlet-factoryonline.com/ coach factory outlet
http://www.toryburch-shoes.com/ tory burch shoes
http://www.coachstoreonline.org/ coach outlet store online
http://www.coachfactory-outletinc.com/ coach factory outlet
http://www.cheapraybansunglasses.us/ cheap ray ban sunglasses
http://www.valentino.us.com/ valentino
http://www.fitfloponline.co.uk/ fitflop uk
http://www.coach-outletinc.com/ coach outlet
http://www.coachoutlet-factorystore.com/ coach outlet store

online
http://www.airjordan.us.com/ air jordan
http://www.timberlandshoesus.com/ timberland shoes
http://www.michaelkorsoutlet-online.us/ michael kors outlet
http://www.coachfactoryoutletnew.com/ coach factory outlet
http://www.coach-factoryoutletinc.com/ coach factory outlet
http://www.truereligionbrandjeans.us.com/ true religion outlet
http://www.truereligionjeans.us.com/ true religion jeans
http://www.coach--handbags.com/ coach outlet online
http://www.louisvuitton--outlet.us/ louis vuitton outlet
http://www.timberland--shoes.com/ timberland boots
http://www.isabelmarantshoes.us.com/ isabel marant shoes
http://www.coachoutletonline-factory.com/ coach outlet online
http://www.michaelkorsoutlet-online.net/ michael kors purses
http://www.louisvuitton-handbag.us/ louis vuitton handbags
http://www.coach-outletstoreonline.com/ coach outlet store

online
http://www.true-religion-jeans.com/ true religion jeans
http://www.coach-outletfactoryonline.com/ coach factory outlet

online
http://www.officialcoachfactoryoutlet.com/ coach factory outlet
http://www.louisvuitton-outlet.org/ louis vuitton outlet
http://www.coach-factoryoutlets.com/ coach factory outlet
http://www.coach-outletonline.us/ coach outlet online
http://www.michaelkorsoutletonlinestore.us/ michael kors outlet
http://www.michaelkorsoutletstoresco.com/ michael kors outlet

store
http://www.tiffanysjewelry-co.com/ tiffany and co jewelry
http://www.celineoutlet-online.com/ celine outlet
http://www.cheap-toms.net/ toms shoes
http://www.celine-handbags.com/ celine handbags
http://www.toms--shoes.us/ toms outlet
http://www.fitflopsandalssale.com/ fitflops
http://www.fitflopusaonline.com/ fitflop outlet
http://www.prada-handbag.com/ prada handbags
http://www.tiffanyandcoinc.com/ tiffany jewelry
http://www.prada-outlet.org/ prada outlet
http://www.michael-korsoutletinc.com/ michael kors
http://www.marcjacobs.us.com/ marc jacobs
http://www.supra.us.com/ supra shoes
http://www.ralphlauren.us.com/ polo ralph lauren
http://www.tiffanyjewelry.us.com/ tiffany jewelry
http://www.shoestoms.net/ toms shoes

__________

POLO says:

2014-08-04 03:00:08

http://www.superbagsmarket.com/ Super Bags Market
http://www.nike-jordanshoes.com/ Nike Jordan Shoes
http://www.thebeatsbydre.net/ Beats By Dre Outlet
http://www.michaelusakors.com/ Michael Kors Outlet Online
http://www.polo-tshirts.com/ Ralph Polo Outlet Online
http://www.northsclearance.com/ North Clearace Outlet
http://www.polo-ralphlaurenonline.com/ Ralph Polo Outlet
http://www.guccishoesuk-2014.net/ Gucci Shoes Outlet
http://www.michaelkorsstates.com/ Michael Kors Outlet
http://www.polooutlet-store.com/ Polo Outlet Store
http://www.ralph-laurenhome.com/ Ralph Lauren UK
http://www.marcjacobsonsale.com/ Marc Jacobs On Sale
http://www.mcmworldwides.com/ MCM Outlet
http://www.salongchamppairs.com/ Sac Longchamp Pairs
http://www.canada-gooser.com/ Canada Goose Outlet
http://www.burberrybags2014.com/ Burberry Outlet
http://www.michaelkors.so/ Michael Kors Outlet
http://www.oakley-sunglassfactory.com/ Oakley Sunglaases Factory
http://www.north-faceoutlet.us.com/ North Face Outlet Online
http://www.moncler-clearance.com/ Moncler Clearance
http://www.woolrich-clearance.com/ Woolrich Clearance
http://www.barbour-jacketsoutlet.com/ Barbour Jackets Outlet Online
http://www.moncler-jacketsoutletonline.com/ Moncler Jackets Outlet Online
http://www.monsterbeatsbydres.net/ Monster Beats Outlet
http://www.louis-vuittonblackfriday.com/ Louis Vuitton Outlet
http://www.lv-guccishoesfactory.com/ Louis Vuitton Factory
http://www.mcmoutlet-jp.com/ MCM 店铺
http://www.cheapdiscountoutlet.com/ Discount Clothes Sale
http://www.michael-korsfactoryonline.com/ Michael Kors Factory Online
http://www.coach-factoryoutlets.net/ Coach Factory Outlet
http://www.coach-blackfriday.net/ Coach Black Friday
http://www.coach-storeoutletonline.com/ Coach Store Outlet Online
http://www.coach-factoryoutletonlines.com/ Coach Factory Outlet Online
http://www.coachcoachoutlet.net/ Coach Outlet
http://www.coach-factory.net/ Coach Factory
http://www.coach-pursesoutlet.net/ Coach Purses Outlet Online
http://www.coach-outletonline.net/ Coach Outlet USA
http://www.mksfactoryoutlet.com/ Michael Kors Factory Outlet
http://www.zxcoachoutlet.com/ Coach Outlet Online USA
http://www.mischristmas.com/ Coach Factory Outlet Online
http://www.misblackfriday.com/ Black Friday
http://www.newoutletonlinemall.com/ Coach Purses Outlet Online
http://www.clickmichaelkors.com/ Michael Kors USA
http://www.cmichaelkorsoutlet.com/ Michael Kors Outlet USA
http://www.ralphlaurenepolo.com/ Ralph Lauren Polo

__________

barbour uk (http://www.iimraipurconfluence.com) says:

2014-11-13 20:16:55

Of particular note is that Vanke,

__________

http://www.taxi-albert.fr (http://www.taxi-albert.fr) says:

2014-11-13 20:34:01

Of particular note is that Vanke,

__________

ylq says:

2017-11-27 23:10:00

http://www.soccershoes-outlet.com/, http://www.mcm-backpacks.com.co/, http://www.raybans-glasses.com.co/, http://www.vans-shoesoutlet.co.uk/, http://www.salvatore-ferragamos.com/, http://www.nike-huarache.co.nl/, http://www.retrojordan-shoes.com/, http://www.christian-louboutinshoesoutlet.com/, http://www.michaelkors.co.nl/, http://www.north-face.com.co/, http://www.marc-jacobs.us.com/, http://www.rosherun-shoes.us/, http://www.ralphlauren-polos.com.co/, http://www.jeans-truereligion.com/, http://www.nikeshoes.de/, http://www.scarpe-hoganshoes.it/, http://www.louboutinshoes.jp.net/, http://www.montblancpences.com/, http://www.air-maxschoenen.co.nl/, http://www.christian-louboutin-shoes.com/, http://www.cheap-jerseys.com.co/, http://giants.nfl-jerseys.org/, http://www.jimmychoo-shoes.com/, http://pelicans.nba-jersey.com/, http://www.rayban-sunglasses.co/, http://www.newbalanceschuhe.com.de/, http://www.outlet-toryburch.com/, http://magic.nba-jersey.com/, http://www.ray-bans.net.co/, http://www.barboursjackets.com/, http://www.longchamps-bags.us.com/, http://www.kate-spadebags.com/, http://www.cheapomega-watches.com/, http://www.michael-korsbags.com.co/, http://www.mbt-outlet.com/, http://pistons.nba-jersey.com/, http://www.outlet-michaelkors.us.org/, http://www.polo-ralphlaurens.us.com/, http://www.oakleysunglasses-canada.ca/, http://www.chiflatironhair.us.com/, http://raiders.nfl-jerseys.org/, http://www.nikeair-max.ca/, http://www.woolrich-jackets.com/, http://www.truereligions.net/, http://www.nike-skos.com/, http://bills.nfl-jerseys.org/, http://www.watches-omega.com/, http://www.raybans-outlet.com.co/, http://www.thenorth-face.com.co/, http://www.nike-shoes.co.nl/, http://www.nike-shoesoutlet.co.uk/, http://www.michaelkors-ins.com/, http://www.jordan-retros.com/, http://www.oakleys-sunglasses.mex.com/, http://www.nba-shoes.com/, http://www.pradas.com.de/, http://www.salvatoreferragamo.us.com/, http://www.raybanoutlet.ca/, http://www.sunglasses-oakleys.com.co/, http://www.crystals-swarovskis.com/, http://www.birkenstocks.com.de/, http://jazz.nba-jersey.com/, http://www.michaels-korsoutlet.com/, http://www.nike-shoes.com.co/, http://www.nike-airmax.com.de/, http://www.nike-airmaxsc.co.uk/, http://www.christian-louboutin.jp.net/, http://www.burberry-storevip.com/, http://www.designer-handbags.com.co/, http://www.ralph-laurens-outlet.com/, http://www.oakleys.org.es/, http://www.skechers-shoesoutlet.com/, http://www.mcm-handbags.org/, http://www.valentino-shoesoutlet.us.com/, http://panthers.nfl-jerseys.org/, http://broncos.nfl-jerseys.org/, http://www.ferragamos.co.uk/, http://www.michael-kors.cc/, http://www.nike-shoesstore.com/, http://www.barbours.us.com/, http://www.basketballshoes.com.co/, http://www.outelt-ralphlauren.co.uk/, http://www.poloralphlauren.com.de/, http://rayban.black-friday.vip/, http://www.babylisspros.com/, http://www.supra-footwears.com/, http://www.converse-schuhe.com.de/, http://www.uhren-stores.de/, http://www.bottega-bags.com/, http://www.adidas-shoes.co.nl/, http://steelers.nfl-jerseys.org/, http://www.okglassesale.com/, http://www.lacosteoutlet.com.co/, http://www.jimmychoos-shoes.com/, http://www.nike-rosherun.com.es/, http://www.michaelkorsoutlet.se/, http://coach.euro-us.net/, http://www.polosoutlet-store.com/, http://www.new-balanceshoes.com/, http://www.outlet-toryburchshoes.com/, http://oakley.black-friday.vip/, http://www.outlet-rayban.co.uk/, http://www.outlet-burberry-bags.com/, http://www.cheap-raybansoutlet.com.co/, http://seahawks.nfl-jerseys.org/, http://nuggets.nba-jersey.com/, http://rockets.nba-jersey.com/, http://www.tommyhilfigers.co.nl/, http://www.raybans-outlet.cc/, http://www.hollister-clothings-store.com/, http://www.burberryoutletonline.com.de/, http://www.tommy-hilfigers.net.co/, http://hawks.nba-jersey.com/, http://www.jordan.com.de/, http://www.new-balanceoutlet.org/, http://www.outlet-michaelkors.com/, http://www.levis-jeansoutlet.com/, http://www.birkenstockshoes.com.de


Add your comment on this article below:

Sorry, there's an error with your form entries. We really appreciate your comment, so please try again.

Form submitting now...

Name:

Website:

Email address (not displayed):

Enter your comment below: