Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-02-2011, 10:03 AM   PM User | #1
philmetz
New Coder

 
Join Date: Aug 2008
Posts: 20
Thanks: 2
Thanked 0 Times in 0 Posts
philmetz is an unknown quantity at this point
Question ajax with php

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:

Code:
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?
philmetz is offline   Reply With Quote
Old 01-03-2011, 07:28 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Maybe it's not appearing because the AJAX call is being executed too fast? What happens if you do something like this:
Code:
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
Code:
print("document.getElementById('test').innerHTML = \"<img src=\"images/load.gif\"/>\";");
you will get this in javascript
Code:
document.getElementById('test').innerHTML = "<img src="images/load.gif"/>";
which is a wrong use of quotes

Last edited by devnull69; 01-03-2011 at 07:31 AM..
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:09 PM.


Advertisement
Log in to turn off these ads.