I would like to create syntactic sugar to Ajax.Response().
Like this:
AjaxGet = function(url) {
ar = new Ajax.Request(url,
{ onSuccess: function(transport) {
alert(transport.responseText);
return transport.responseText;
}
});
return ar.responseText;
}
So that
title = AjaxGet('/favouriteMovie?horrors=true')
would store to title variable result of Ajax request.
But the function code above is not working, not returning responseText
You can only do this if you use synchronous Ajax, which you should never ever do. The user interface of the whole browser will become unresponsive for the duration of the request, which you have no way to predict.
So the best you can do will involve a callback of some sort:
There are problems with this approach, though:
For these reasons I recommend you go with the full
Ajax.Requestwhenever you need it.