473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Ajax refresh problem

118 100+
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?

Expand|Select|Wrap|Line Numbers
  1. function createRequestObject() {
  2.  
  3.    var req;
  4.  
  5.    if(window.XMLHttpRequest){
  6.       // Firefox, Safari, Opera...
  7.       req = new XMLHttpRequest();
  8.    } else if(window.ActiveXObject) {
  9.       // Internet Explorer 5+
  10.       req = new ActiveXObject("Microsoft.XMLHTTP");
  11.    } else {
  12.       // There is an error creating the object,
  13.       // just as an old browser is being used.
  14.      alert("Your Browser Does Not Support This Script - Please Upgrade Your Browser ASAP");
  15.    }
  16.  
  17.    return req;
  18.  
  19. }
  20.  
  21. // Make the XMLHttpRequest object
  22. var http = createRequestObject();
  23.  
  24. function sendRequest(page) {
  25.  
  26.    // Open PHP script for requests
  27.    http.open('get', page);
  28.    http.onreadystatechange = handleResponse;
  29.    http.send(null);
  30.  
  31. }
  32.  
  33. function handleResponse() {
  34.  
  35.    if(http.readyState == 4 && http.status == 200){
  36.  
  37.       // Text returned FROM the PHP script
  38.       var response = http.responseText;
  39.  
  40.       if(response) {
  41.          // UPDATE ajaxTest content
  42.          document.getElementById("captch").innerHTML = response;
  43.       }
  44.  
  45.    }
  46.  
  47. }
  48.  
  49. function repeatloop()
  50. {
  51. sendRequest('captch1.php'); 
  52. setTimeout("repeatloop()", 2000);
  53. }
  54.  
  55. window.onload=function() {
  56. repeatloop();
  57. }
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

http://helraizer.dnsalias.net/cap/GIF87a%EF%BF%BD

is there anyway to change this with the code I have/another way?

Sam
Dec 13 '07 #1
1 1602
acoder
16,027 Expert Mod 8TB
Create the image on the server-side, return the image source as the Ajax response and change the src of the img element to the created image.
Dec 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Beshoo | last post by:
hey gaiz plz I want to cerate log in system in ajax i do it but i have one problem AFTER I start thes session then press refresh key the session gone !!! in other words , after the user type hid...
10
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e....
25
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e....
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
5
by: Kaante | last post by:
Hi, I basically have two frames on my page, the top one contains users stats and the bottom frame contains the website. I want to have a message icon on the top frame which would flash once the...
1
by: urbn | last post by:
Hi everyone. I am finally starting to focus more time on learning AJAX for the last few days, and I ran into a problem I couldn't find a solution too, or find much info on how to do this. What...
1
by: luigi.corrias | last post by:
Hello everybody, this is a very difficult question… imagine 2 webform asp.net A and B B is an iframe inside A..
4
kelleyvanevert
by: kelleyvanevert | last post by:
Hello everyone, This question is often asked, and I know there are lots and lots of answers that I could be using, but I just want a clear good answer. I am making a website (for playing a game...
4
by: eihabisaac | last post by:
hi all i want to refresh a div using ajax, i wrote this code: index.php <script src="ajax/moniter/moniter.js" type="text/javascript"></script> <body onload="moniter();"> <div id="moniter">
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.