The crappy thing about html returned from ajax calls is that the returned html doesn't execute any javascript "onload" calls. This function is called on an ajax success AFTER the called html has been placed inside the ajax target div. The function finds any "onload" javascripts inside "script" tags and eval()'s them. This is necessary for wysiwyg editor elements inside returned html from ajax calls as well as multilayer ajax calls.
function core_activate_ajax_scripts(containerObject)
{
childNodeArray = containerObject.childNodes;
scripts = containerObject.getElementsByTagName("script");
if(scripts.length>0)
{
for(var n=0;n
{
eval(scripts[n].innerHTML);
}
}
}
/////////////////////////
//example call
/////////////////////////
function getSelect(value,otherValue)
{
// define url
var url = "/modules/Query-GFF/controllers/ajax/get_select.php";
var response = new Ajax.Request( url,
{
method: "post",
parameters:
{
'value': escape(value),
'othervalue': otherValue
},
onSuccess: function(transport)
{
var result = transport.responseText;
//create the target div object
target_object = document.getElementById('my_target_div');
//place the ajax returned html in the target div
target_object.innerHTML = result;
//execute any javascript elements that require an "onload""
core_activate_ajax_scripts(target_object);
}
}
);
}