Question : Ajax Response events do not fire , using Mongrel with Ruby and Prototype.

Goodafternoon,

I have got a minimum Mongrel instance running (see ruby code) and i am hitting it with an Ajax request using Prototype. (see javascript code) I get the 'onLoading' event, but the other events never fire. I am getting the response because I can see the response from the Mongrel server in my NET monitor (Firebug). But the events never fire (no oncomplete and or onfailure)

Can anyone see what I am doing wrong? Do I need to add something more  to the header in Mongrel?

Also i'm using the cross site ajax plugin to do cross Site Ajax calls. (hence the crossSite:true) and trace does a write to the firebug console.

Thank you very very much
kind regards,
Marco Kotrotsos

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
//Javascript
 
function request() {
 
	trace('start');
	new Ajax.Request('http://localhost:3000/test', {
	  method: 'GET',
	  crossSite: true,
 
		  onLoading: function(transport) {
		  trace('onLoading' );    
		  },
		  onComplete: function(transport) {
		  trace('onSuccess');
		  trace('The message is '+message);
		  },
		  onFailure: function() {
		  trace('onFailure');
		  }
});
}
 
//ruby
 
 class SimpleHandler < Mongrel::HttpHandler
    def process(request, response)
      response.start(200) do |head,out|
        head["Content-Type"] = "text/javascript"
        out.write("var message = 'hello';\n")
      end
    end
 end
 
 h = Mongrel::HttpServer.new("127.0.0.1", "3000")
 h.register("/test", SimpleHandler.new)
 h.run.join
Open in New Window Select All

Answer : Ajax Response events do not fire , using Mongrel with Ruby and Prototype.

@marco...  Found the problem.

The line of code shown below needs to go in your AjaxHandler#process method, between lines 21 and 22 in the code snippet above, along with the crossSite: true (lines 52/53), in the Ajax.Request code, and the javascript include for the plugin (lines 46/47).

The documentation for the crossSite plugin mentions this at
   http://www.mellowmorning.com/2007/10/25/introducing-a-cross-site-ajax-plugin-for-prototype/
but doesn't really make it clear that this is required. Without it, you get a javascript error (which showed up in Firebug).

I am now able to invoke index.html from "file:///c:... etc" and then send the Ajax request to "http://localhost:4000/ajaxpage" -- a cross-site request that overcomes the Single Original Policy --  and get the result.

HTH...jon
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
// Add this between lines 21/22 above [the out.write(...) commands]
 
        out.write('var _xsajax$transport_status = 200;')
 
// Add this between lines 52/53 above to add the crossSite feature
 
        out.write('var _xsajax$transport_status = 200;')
 
// Add this between lines 46/47 to load the plugin
 
	
Open in New Window Select All
Random Solutions  
 
programming4us programming4us