I have tried many online tutorials and examples nothing much paid off..
I need to run the js from HTML Response in Ajax.
My Code:
<script src="prototype.js" type="text/javascript"></script>
<script type="text/javascript">
function showmsg()
{
new Ajax.Updater('main', 'getmsg.php?q=1', { method: 'get' },{evalScripts:true});
}
</script>
getmsg.php contains: (testing purpose)
$q=$_GET[q];
Header("content-type: application/x-javascript");
if ($q==1)
echo 'hi
<script type="text/javascript">
type = function(){
var a =2;
if(a>1)
alert(\'random number 87\');
}
type();
</script>';
I need to run this type() function in main page after ajax call. But the output is just 'hi'
PS: if this script works, will it work on all browsers?
Can someone please help me out..
I think you just missbuilt your parameters array, try this :
new Ajax.Updater('main', 'getmsg.php?q=1', { method: 'get', evalScripts:true});