aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes help with Prototype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "help with Prototype" Watch "help with Prototype" New topic
Author

help with Prototype

kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
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 ]

Who dares, wins! (SAS motto)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

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").


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
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 ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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});


GenRocket - Experts at Building Test Data
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Do you have a javascript function that looks like this?



The onSuccess defines a call back method that you need to implement.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

I see no function named "handler" defined in your code.
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with Prototype