I wish to run a script after a component is ajax loaded. To achieve
that, I attempted to set the web2py-component-command as follows:
======================
<!-- Reload comments component at regular intervals-->
comment_component = function(){
t = $('#comment_text__row textarea').val();
{{response.headers['web2py-component-command']="console.log('yay')"}}
web2py_component('/roverus/comment/create.load?current_conversation='
+ current_conversation,'conversation');
}
setInterval("comment_component()", 5000);
======================
However "console.log('yay')" does not run.
I also set web2py-component-command in the related function as
follows:
==========================
function web2py_ajax_page(method,action,data,target) {
{{response.headers['web2py-component-
command']="console.log('yay2')"}} <---------------------added line
jQuery.ajax({'type':method,'url':action,'data':data,
'beforeSend':function(xhr) {
xhr.setRequestHeader('web2py-component-
location',document.location);
xhr.setRequestHeader('web2py-component-element',target);},
'complete':function(xhr,text){
var html=xhr.responseText;
var content=xhr.getResponseHeader('web2py-component-content');
var command=xhr.getResponseHeader('web2py-component-command');
var flash=xhr.getResponseHeader('web2py-component-flash');
var t = jQuery('#'+target);
if(content=='prepend') t.prepend(html);
else if(content=='append') t.append(html);
else if(content!='hide') t.html(html);
web2py_trap_form(action,target);
web2py_ajax_init();
if(command) eval(command);
if(flash) jQuery('.flash').html(flash).slideDown();
}
});
}
======================
This too does not work.
Can anyone enlighten me if I misunderstood the syntax, or is there
another way I can get this working? Thanks in advance.