T
trpost
Is it possible to execute javascript as passed in xmlHttp.responseText
Here is what I am doing:
search.js
var xmlHttp
xmlHttp=GetXmlHttpObject()
var url="search.php"
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("search").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
search.php
<script type="text/javascript">
alert("hi");
</script>
<?php echo "hi"; ?>
test.php
<script src="search.js"></script>
<div id=livesearch></div>
So what I see when I browse to test.php is 'hi' printed to the
browser, but I would also expect to have the javascript alert executed
If I visit search.php then I get 'hi' printed to the browser and the
alert message
So it seems that when I pass the response to the span the javascript
alert is ignored
(document.getElementById("search").innerHTML=xmlHttp.responseText
Sp my question is how can I have javascript be passed and executed?
Thanks!
Here is what I am doing:
search.js
var xmlHttp
xmlHttp=GetXmlHttpObject()
var url="search.php"
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("search").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
search.php
<script type="text/javascript">
alert("hi");
</script>
<?php echo "hi"; ?>
test.php
<script src="search.js"></script>
<div id=livesearch></div>
So what I see when I browse to test.php is 'hi' printed to the
browser, but I would also expect to have the javascript alert executed
If I visit search.php then I get 'hi' printed to the browser and the
alert message
So it seems that when I pass the response to the span the javascript
alert is ignored
(document.getElementById("search").innerHTML=xmlHttp.responseText
Sp my question is how can I have javascript be passed and executed?
Thanks!