Topic: Rails and XMLHTTPRequest.readyState

Hello,

I'm new here so be gentle.

At any rate, I am developing a mapping application and am using Rails for the back end.  Separate from the backend I have developed an AJAX based page that does really nice mapping.  I know that Rails has a built in JS framework, but I don't quite have the time to learn it at this time (demo in a week).  At any rate here's the problem ...

In the page, I create an array of XMLHTTPRequest objects and send them off calling a Rails controller (they are calling the controller to make a map tile a la Google Maps).  I assign all of the request objects to a onreadystatechange event handler with themselves as a parameter (in order to get a handle on them).  The problem I'm having is that I never get past readyState 0.  So while I can see the controller completing it's tasks, the javascript is never notified of this.  Am I perhaps missing something?  Or should I just bite the bullet and rewrite this in the Rails framework?

Thanks,
Clark

Re: Rails and XMLHTTPRequest.readyState

Sorry I don't know enough to answer your question (perhaps someone else does?). But, I recommend giving Prototype and the rails AJAX helper methods a go. 99% of the time it just takes a few lines of code and no JavaScript to do the majority of AJAX stuff, especially if you use RJS.

If you are wondering how to do something specific with AJAX and Rails, feel free to ask here. I'd be willing to provide the code necessary to accomplish it.

The only reason I can see not doing this is if you've already AJAXified most of your application and are just hung up on this last thing. That or you want something lighter-weight than Prototype which is understandable.

Railscasts - Free Ruby on Rails Screencasts

Re: Rails and XMLHTTPRequest.readyState

It's mainly that I want something really light weight.  Essentially the only XMLHTTPRequest I'm doing is to have the server side create an image, the only piece of information I need from the call is when it completes.  I've tried "render_text" with no luck.  I may take a look at Prototype, it's just that it appears to be a bigger time investment that I have left.

Thanks,
Clark

Re: Rails and XMLHTTPRequest.readyState

Use the PrototypeHelper class methods to send Ajax requests instead of creating a XMLHttpRequest object and sending a request.