I am trying to learn a little about ajax and prototype.js.

Here's what I have so far:

boardtest.php

<html>
<head>
<title>AJAX Test with new javascript</title>
<script src="scripts/prototype.js" type="text/javascript"></script>
<script src="scripts/ajax.js" type="text/javascript"></script>
</head>
<body>
<div id="products">(...locaing inventory...)</div>
</body>
</html>

ajax.php

<?php

$company = $_GET['company'];
$limit = $_GET['limit'];

$line = "The company, ".$company.", has ".$limit." employees.";
echo $line;
?>

ajax.js

new Ajax.Updater('products', '/ajax.php', {
  method: 'get',
  parameters: {company: 'example', limit: 12}
});

and, of course, prototype.js, which is the standard .js file.

I know I am doing, or not doing, something that will be completely obvious to anyone who has used prototype before, but this is day 1 for me. In my effort, I get the error:

Uncaught ReferenceError: Ajax is not defined scripts/ajax.js:1

Any thoughts?

EDIT: Minor change, same error. :(

Uncaught ReferenceError: Ajax is not defined scripts/ajax.js:1
Any thoughts?

yes, you can't prototype from a nonexisting object!

yes, you can't prototype from a nonexisting object!

I don't suppose that you could clarify that a bit, could you? That answer is, in effect, just telling me that I am wrong with little else to go on.

Again, this is my first venture into using prototype.js. I am not asking anyone here to do all of the code for me, just point out what I am doing wrong and maybe slip in a clue as to what to do to make it right. An online example would do nicely.

"Ajax is not defined" - says it all.
Meaning ther is no 'Ajax' object. Not even in jour js file. Otherways, the syntax "new Ajax " would be correct.

commented: Troy is kind of being a dick and not helping solve the problem. +0

Easy Troy, Ajax is defined inside the prototype library. If I had to guess, his own ajax.js is executing before prototype has finished its business. Try wrapping the stuff in ajax.js in a function that is called by the onload event of the body. Its also possible that prototype hasn't loaded at all, in which case just make sure you have the correct path to the file specified.

commented: Great response. Reminded me to remember the basics. +1

Easy Troy, Ajax is defined inside the prototype library.

I don't know, I haven't seen it. Did you. What if prototype.js is empty, or if there is no Ajax object defined there at all?

If I had to guess, his own ajax.js is executing before prototype has finished its business. Try wrapping the stuff in ajax.js in a function that is called by the onload event of the body. Its also possible that prototype hasn't loaded at all, in which case just make sure you have the correct path to the file specified.

That's what I've said.
He/she is trying to prototype from object named Ajax, which simply isn't there!
To make sure it's something else - we'll have to see the source first.

Easy Troy, Ajax is defined inside the prototype library. If I had to guess, his own ajax.js is executing before prototype has finished its business. Try wrapping the stuff in ajax.js in a function that is called by the onload event of the body. Its also possible that prototype hasn't loaded at all, in which case just make sure you have the correct path to the file specified.

I feel a little silly. Normally, the path is the first thing that I check. It was one of those "hang your head and laugh until you cry" moments. The path was fixed, and now everything works.

TroyIII - I thought that the length and standard of prototype.js didn't need to be re-supplied. If you need to see the source, you can download it from: prototypejs.org.

commented: otherwise- that's not prototyping that's a new instance. For prototyping you need to use the actual word 'prototype'.. +0

I feel a little silly. Normally, the path is the first thing that I check. It was one of those "hang your head and laugh until you cry" moments. The path was fixed, and now everything works.

TroyIII - I thought that the length and standard of prototype.js didn't need to be re-supplied. If you need to see the source, you can download it from: prototypejs.org.

As you see, you need to learn to trust them 'error reports'!
If its says "Ajax is not defined", it means its not. it isn't there.

That's why [when you are at knowlledge that the call to is defined] you first check if the source is right. That is, if the actual file is at the location exactly specified or not.
My stating that your script is correct, would be good enough for you to foresee the posibility that your reference to it might be wrong.
But since you were so certain that it was right, I had to pressume that its either the wrong content in the referenced file or that the whole content might be missing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.