Ad:
 
Similar Threads
Feb 25th, 2010
0

Quick question about prototype.js

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

Here's what I have so far:

boardtest.php
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>AJAX Test with new javascript</title>
  4. <script src="scripts/prototype.js" type="text/javascript"></script>
  5. <script src="scripts/ajax.js" type="text/javascript"></script>
  6. </head>
  7. <body>
  8. <div id="products">(...locaing inventory...)</div>
  9. </body>
  10. </html>

ajax.php
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $company = $_GET['company'];
  4. $limit = $_GET['limit'];
  5.  
  6. $line = "The company, ".$company.", has ".$limit." employees.";
  7. echo $line;
  8. ?>

ajax.js
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. new Ajax.Updater('products', '/ajax.php', {
  2. method: 'get',
  3. parameters: {company: 'example', limit: 12}
  4. });

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.
Last edited by Wraithmanilian; Feb 25th, 2010 at 2:39 pm. Reason: Poster is an idiot. :)
Reputation Points: 13
Solved Threads: 28
Junior Poster
Wraithmanilian is offline Offline
141 posts
since Dec 2009
Feb 26th, 2010
0

Re: Quick question about prototype.js

Quote ...
Uncaught ReferenceError: Ajax is not defined scripts/ajax.js:1
Any thoughts?
yes, you can't prototype from a nonexisting object!
Reputation Points: 101
Solved Threads: 46
Posting Whiz
Troy III is offline Offline
365 posts
since Jun 2008
Feb 26th, 2010
-1

Re: Quick question about prototype.js

Click to Expand / Collapse  Quote originally posted by Troy III ...
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.
Reputation Points: 13
Solved Threads: 28
Junior Poster
Wraithmanilian is offline Offline
141 posts
since Dec 2009
Feb 27th, 2010
-1

Re: Quick question about prototype.js

"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.
Reputation Points: 101
Solved Threads: 46
Posting Whiz
Troy III is offline Offline
365 posts
since Jun 2008
Feb 27th, 2010
0

Re: Quick question about prototype.js

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.
Reputation Points: 11
Solved Threads: 2
Newbie Poster
gstephas is offline Offline
4 posts
since Feb 2010
Feb 27th, 2010
-1

Re: Quick question about prototype.js

Click to Expand / Collapse  Quote originally posted by gstephas ...
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?
Quote ...
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.
Reputation Points: 101
Solved Threads: 46
Posting Whiz
Troy III is offline Offline
365 posts
since Jun 2008
Feb 27th, 2010
-1

Re: Quick question about prototype.js

Click to Expand / Collapse  Quote originally posted by gstephas ...
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.
Reputation Points: 13
Solved Threads: 28
Junior Poster
Wraithmanilian is offline Offline
141 posts
since Dec 2009
Feb 27th, 2010
0

Re: Quick question about prototype.js

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.
Reputation Points: 101
Solved Threads: 46
Posting Whiz
Troy III is offline Offline
365 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Expected identifier, string or number
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: scrolling issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Build Custom RSS Feed


Follow us on Twitter


© 2010 DaniWeb® LLC