• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

help with Prototype

 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In prototype, there's a function called Ajax.Request, which trying but I'm having difficulty understanding it.

Here is a sample script from a very good online tutorial:



My question is this:

The function "showResponse()", which is passed to Ajax.Request, calls another function "originalRequest()". No mention is made of this "originalRequest()" function in the tutorial, and I have no idea what it means. I have emailed the author twice and he said this:

The function you pass in will be called by the object with two arguments, the first one will be the XMLHttpRequest
To be clear, it is the XmlHttpRequest object that carried out the request/response. There's no reference to myAjax in the callback.



Not sure what this means.
I have some Ajax code that is currently not working, and I feel this is the reason. I have tried creating XHR object and passing it in, but that did not work. Please help!!!
[ July 18, 2007: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kwame Iwegbue:
The function "showResponse()", which is passed to Ajax.Request, calls another function "originalRequest()"



No, it doesn't. Where do you see a function call? The name originalRequest is the parameter that is passed to the showResponses function. It is a reference to the XMLHttpRequest instance used to make the Ajax call.

Not sure what this means.



Do you understand how functions are called and passed parameters?

I have tried creating XHR object and passing it in,



No, it is passed for you.

I have some Ajax code that is currently not working



If you follow the pattern of the tutorial, it should work.

And by the way, when talking about the Prototype library, be sure to capitalize the "P". Otherwise, it could be confused with a constructor's prototype property (with a small "p").
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear. I understand now. Also I understood already how functions are passed parameters. My issue was that, it just wasn't explained well in the tutorial. Now you've explained it.

I'm still unable to make my code work though.



It looks like everythings in place, yet it doesn't work. I'm not so sure anymore that its an Ajax or Prototype problem. Could simply be a Javascript syntax issue on my part. Either way I would surely appreciate some help.

(p.s i had to re-write onclick and eval because this system won't allow them in the code)
[ July 18, 2007: Message edited by: kwame Iwegbue ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, without knowing what exactly "it doesn't work" means, my first guess is this:

new Ajax.Request(form.action, {method:'post', postBody : params, onSuccess: handler});

postBody should be parameters

new Ajax.Request(form.action, {method:'post', parameters : params, onSuccess: handler});
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Greg. The code comes from the Stripes Ajax page.

By it doesn't work, I mean there's something in this script block thats either not proper syntax or just not the way its supposed to be. It doesn't matter what test code I put in the 'update' function, its simply not being called:



I've even tried calling onFailure:



However, if I replace 'handler' in onSuccess: handler, with alert('works'), it produces an alert box!. Whats that about?
[ July 18, 2007: Message edited by: kwame Iwegbue ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a javascript function that looks like this?



The onSuccess defines a call back method that you need to implement.
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see no function named "handler" defined in your code.
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm finally getting somewhere. Someone on the Stripes forum recommended I use Firebug, a Firefox pluggin. It did great. Turns out the problem is a missing closing curly brace, and innerHtml should be innerHTML. The code gets to the server now, but I'm still not getting a result. Instead the Result span reads: [object Object]
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kwame Iwegbue:
Instead the Result span reads: [object Object]



That's what you get when an instance of Object gets serialized to a string.
 
He's giving us the slip! Quick! Grab this tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic