How To Execute A page contain javascript function in AJAX Response?

Hi,

How To Execute A page contain javascript function in AJAX Response?

Ajax Response
<script type=“text/javascript”>
function muthu(){
alert(‘hai’);
}
</script>
<script type=“text/javascript”>
function muthu123(){
alert(‘hai123’);
}
</script>
<script type=“text/javascript”>
function muthu1234(){
alert(‘hai1234’);
}
</script>

MuthuRaja

You could use innerHTML to place it somewhere within the page. The scripts should be accessible then.

Hi Paul,

Its not Working.

My indexpage.html code here

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head></head>
<body>
<div id=“show”></div>
<input type=“button” value=“makeReq” onClick=“makeReq()” />
<input type=“button” value=“muthu” onClick=“muthufn()” />qwer
<script>
function makeReq(){
mR(‘getScript.html’,cFn,‘’);
}
mR=function(a,b,c,d){d=this.ActiveXObject;d=new(d?d:XMLHttpRequest)(‘Microsoft.XMLHTTP’);d.open(c?‘POST’:‘GET’,a,1);d.setRequestHeader(‘Content-type’,‘application/x-www-form-urlencoded’);d.onreadystatechange=function(){d.readyState>3&&b?b(d.responseText,d):0};d.send(c)}

function cFn(res){
document.getElementById(‘show’).innerHTML=res;
eval(document.getElementById(‘show’));
}
</script>
</body>
</html>

getScript.html Code Here

<script type=“text/javascript”>
function muthufn(){
alert(‘hai’);
}
</script>

After I click muthu button, muthufn is not defined error throw.

MuthuRaja

By default javascript through Ajax is treated as a string like all other data been passed unless given a method type to be parsed as. [B]eval/B which isn’t the best thing to use anymore will activate any javascript source that is dynamically added to the page unless you run an interval until the source is active.