There should be a simple solution this this issue but I am not being able to figure it out!! So I am getting data/templates via ajax. And there are some function in the ajax data. When I try to call the function it throws and error. Example in jsfiddle with regular vs ajax function calls. http://jsfiddle.net/rexonms/b05uxko6/
<!-- HTML -->
<div id="regularData">
<h2>Regular Data</h2>
<p onclick="mouseEvent()">Click Me</p>
<script>
function mouseEvent(){
alert('Yep clicked');
}
</script>
</div>
<hr>
<div id="ajaxData"></div>
<!-- Javascript -->
var request = new XMLHttpRequest(); // do we need this?
request.open("POST", "https://kvdevl06.sohalo.com/apps/kobie/php/widget/dispatcher_tpl.php");
request.onreadystatechange = function(){
if(request.readyState === 4){
alert('Ajax data is: ' + request.response);
document.getElementById("ajaxData").innerHTML = request.response;
}
}
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send("action=getTest&partner_user_id=1&template_id:test");