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 12-13-2007, 03:43 PM   PM User | #1
helraizer
New Coder

 
Join Date: Nov 2007
Posts: 61
Thanks: 0
Thanked 6 Times in 6 Posts
helraizer is an unknown quantity at this point
AJAX refresh

Hi folks,

I have an AJAX script to refresh a certain element in the page. The problem is that the element I need it to refresh is a dynamic image.. but the way I've done it inserts the raw image into the browser, thus just comes up with gobbledy gook characters and symbols. Would there be any way to do this? or would there be another approach?

Code:
function createRequestObject() {

   var req;

   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
     alert("Your Browser Does Not Support This Script - Please Upgrade Your Browser ASAP");
   }

   return req;

}

// Make the XMLHttpRequest object
var http = createRequestObject();

function sendRequest(page) {

   // Open PHP script for requests
   http.open('get', page);
   http.onreadystatechange = handleResponse;
   http.send(null);

}

function handleResponse() {

   if(http.readyState == 4 && http.status == 200){

      // Text returned FROM the PHP script
      var response = http.responseText;

      if(response) {
         // UPDATE ajaxTest content
         document.getElementById("captch").innerHTML = response;
      }

   }

}

function repeatloop()
{
sendRequest('captch1.php'); 
setTimeout("repeatloop()", 2000);
}

window.onload=function() {
repeatloop();
}
at the moment the image is in a 'span' element. If I change innerHTML to src, and the element to img, it puts the element src to

Quote:
"http://helraizer.dnsalias.net/cap/GIF87a%EF%BF%BD"
is there anyway to change this with the code I have/another way?

Sam
helraizer is offline   Reply With Quote
Old 12-13-2007, 04:04 PM   PM User | #2
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
Can't you just change the src of the image instead of getting the page with AJAX..?
Mwnciau is offline   Reply With Quote
Old 12-13-2007, 04:16 PM   PM User | #3
helraizer
New Coder

 
Join Date: Nov 2007
Posts: 61
Thanks: 0
Thanked 6 Times in 6 Posts
helraizer is an unknown quantity at this point
Quote:
Originally Posted by Mwnciau View Post
Can't you just change the src of the image instead of getting the page with AJAX..?
Possibly, but I wanted the image to change every 60 seconds (i know the code was set to 2), without having to refresh the entire page. Would that be possible?
helraizer is offline   Reply With Quote
Old 12-13-2007, 04:19 PM   PM User | #4
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
PHP Code:
var 0// to stop caching of the image
setInterval(" document.getElementById('image').src='image.jpg?'+i;  i++; "60000); 

Last edited by Mwnciau; 12-13-2007 at 04:26 PM..
Mwnciau 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 02:23 AM.


Advertisement
Log in to turn off these ads.