In need of the AJAX code.

+1 Paul Pops · January 20, 2015
Is there a place to get the code to this AJAX tutorial up through lesson 11?

I did the first part and it did not interact.

This is what I have and I don't have the code to check it with.

header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UT-8" standalone="yes" ?>';

echo '<response>';

$food = $_GET['food'];
$foodArray = array('tuna', 'bacon', 'beef', 'loaf', 'ham');
echo 'We do have '.$food.'!';
elseif($food==' ')
echo 'Enter a food please';
echo 'Sorry friend, we dont sell no '.$food.'!';

echo '</response>';


// JavaScript Document

var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject() {

var xmlHttp; 

if(window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e) {
xmlHttp = false;
xmlHttp = new XMLHttpRequest();
}catch(e) {
xmlHttp = false;

alert("cant create that object.");
return xmlHttp;

function process(){
if(xmlHttp.readyState==4 || xmlHttp.readyState==4) {
food = encodeURIComponent(document.getElementById("userInput").value);"GET", "foodstore.php?food=" + food, true); 
xml.onreadystatechange = handleServerResponse;



function handleServerResponse() {
if(xmlHttp.readyState==4) {
if(xmlHttp.status==200) {
xmlResponse = smlHttp.responseXML;
xmlDocumentElement = smlResponse.documentElement;
message =;
document.getElementById("underInput").innerHTML = '<span style="color:blue">' + message + '</span>';

alert('something went wrong!');

<!doctype html>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="foodstore.js"></script>


<body onload="process()">

<h3>The Food Basket</h3>
Enter the food you would like to order:
<input type="text" id="userInput" />

<div id="underInput" />

Post a Reply


Oldest  Newest  Rating
0 Paul Pops · January 25, 2015
Inzamam, or anyone?

Could you please post the correct code for AJAX tutorials  18 - 20 if you have it.
It is the part that covers "Things in my pocket" with CSS and Javascript.
0 Inzamam Tahir · January 21, 2015
Well, I did not read the whole code though but I did get the idea that you want the complete working code up to tutorial 11 and you can get that by visiting the link below

I hope this is exactly what you want.
0 Paul Pops · January 22, 2015
Thanks Inzaman!

Once I get the hang of the stuff up to 11, I will hopefully be able to move on to 12 and beyond. 
The correct code will help the learning process.
The videos so far have been very good.  
0 Paul Pops · January 22, 2015
The code is working! Thank you! 

I found a small spelling error in the "Microsofot.XMLHTTP"            JS page. It doesn't affect the outcome.
  • 1



A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.