tags:

views:

371

answers:

2

This question is somewhat related to my previous question (not necessary to go through it) link text , although this one is more of an Ajax problem.

I tested my page in firebug and I am getting the following error

Event.Observe is not a function

Event.observe('form908983160', 'submit', function(event) { new Ajax.Updater('comments','/blog/posts/comments/add', {asynchronous:true, evalScripts:true, parameters:Form.serialize('form908983160'), requestHeaders:['X-Update', 'comments']}) }, false);

I am using the prototype framework for developing my cake php application. How should I fix this problem? Guys, I really need your help in this one. I am really stuck at this one. [:(]

+1  A: 

prototype.js has to be :

  • loaded in the page (verify it's not in 404, for instance)
  • loaded in the page before the execution of your script

Which generally means you need to include prototype.js first, and, only after that, you can include your scripts.

As a sidenote : you are not using any other JS Framework in that page, of course...

Pascal MARTIN
As I am using cake php for my application, my prototype.js file lies in the app/webroot/js folder. Moreover,I have added $javascript->link(array('prototype')) in default.ctp file to produce a link to the javascript file. What else should I do?
Learner
A: 

Remember that any Event.observers need to be used in global

 Event.observe(window,'loaded',f);
// or 
Event.observe(document,'dom:loaded',f)

otherwise they will not work.

For me it looks like there's problem with linking to Prototype. Open firebug and try to see the contents of your script files - if you see html, that means something went terribly wrong :-)

Plugawy