There are two ways that I know of with Request.HTML. By default, evalScripts is set to true. If you set the ‘update’ to $(‘refresh-box’
, it will work.
function ajaxRequest(){ new Request.HTML({ url: 'post.php', update: $('refresh-box') }).send(); }
By default, the method is post and you do not have to specify any data. Normally you would add the ‘data’ in the send() method anyway. Now, this works great for the most part. But, if you are like me, you do more then just update the content within an element. For that, something like the following will work:
function ajaxRequest(){ new Request.HTML({ evalScripts: false, url: 'post.php', onSuccess: function(html, elements, tree, javascript) { $('refresh-box').set('text', ''); $('refresh-box').adopt(html); if (javascript) $exec(javascript); }, onFailure: function() { $('refresh-box').set('text', 'The request failed.'); } }).send(); }
var myRequest = new Request({
url: '/addmodule',
method: 'post',
onRequest: function(){
myElement.set('text', 'loading...');
},
onSuccess: function(responseText){
myElement.set('html', responseText);
},
onFailure: function(){
myElement.set('text', 'Sorry, your request failed :(');
}
});
var myHTMLRequest = new Request.HTML({
url: '/addmodule',
evalScripts : false,
evalResponse : true,
onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
alert(responseHTML)
var sc = '<script type="text/javascript">';
sc+= responseJavaScript + '</script>';
myElement.set('html',responseHTML).highlight();
}
});