...

View Full Version : ajax with php



philmetz
01-02-2011, 11:03 AM
I have a function using Ajax to get data and while it gets the data a loading image appears but its not appearing, something wrong with the <img> syntax:



print("
<script type=\"text/javascript\">
var http = false;

http = new XMLHttpRequest();

function validate(user) {
http.abort();
document.getElementById('test').innerHTML = \"<img src=\"images/load.gif\"/>\";
http.open(\"GET\", \"tracks.php?name=\" + user, true);
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('test').innerHTML = http.responseText;
}
}
http.send(null);
}
</script>
");


How do i fix that?

devnull69
01-03-2011, 08:28 AM
Maybe it's not appearing because the AJAX call is being executed too fast? What happens if you do something like this:


var http = null;
function validate(user) {
http.abort();
document.getElementById('test').innerHTML = '<img src="images/load.gif"/>';
window.setTimeout(function() {request(user);}, 2000);
}

function request(user) {
http.open("GET", "tracks.php?name=" + user, true);
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('test').innerHTML = http.responseText;
}
}
http.send(null);
}


EDIT: Ah, and even more important. By doing this


print("document.getElementById('test').innerHTML = \"<img src=\"images/load.gif\"/>\";");

you will get this in javascript


document.getElementById('test').innerHTML = "<img src="images/load.gif"/>";

which is a wrong use of quotes



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum