Sending GET data with AJAX to another file, I include
echo "<script>alert('Something');</script>";
in the other file. This content is then dynamically displayed using AJAX.
var ajaxDisplay = document.getElementById('edit');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
The above code puts the
<script>alert('Something');</script>
inside a div named edit. However, no alert is shown. How can I make it work?
I have a mix of HTML and JavaScript in my project. Below is a snippet of the code:
function ajaxFunctions(){
var ajaxRequest; // The variable responsible for enabling Ajax!
try{
// Compatible with Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// For Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// An error occurred
alert("Your browser broke!");
return false;
}
}
}
// Create a function to receive data from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('edit');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var namef = document.getElementById('nameed').value;
var queryString = "?namef=" + namef;
ajaxRequest.open("GET", "try.php" + queryString, true);
ajaxRequest.send(null);
}
Is it a good idea to locate the script tags and use eval? But how can I identify the script tags?