473,398 Members | 2,389 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,398 software developers and data experts.

Image through Ajax not loading correctly.

5
Hello. I'm trying to make some kind of image gallery with php and javascript (w/ ajax), but I've run into some problems.

The basic idea is the following: I've got a <span> tag and, when I click a button, the inner html of the tag changes to <img src="x" />. The problem is that, unless the image is small -less than 80kB-, it won't load properly. Some browsers won't display it entirely, some others won't even show it.

The code related to it:
Expand|Select|Wrap|Line Numbers
  1. var xmlHttp;
  2.  
  3. function Ajax(data, url, method) {
  4.   try
  5.     {
  6.       xmlHttp = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
  7.     } catch (e) {
  8.           try {
  9.             xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
  10.               } catch (e) {
  11.                   try{
  12.                      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  13.                       }catch (e){
  14.                         alert("Your browser does not support AJAX!");
  15.                         return false;
  16.                                  }
  17.                             }
  18.                    }
  19.  
  20.     xmlHttp.onreadystatechange = function() {
  21.         if (method == 'updatePhoto') updatePhoto();
  22.         if (method == 'getPhotoCount') getPhotoCount();
  23.     };
  24.  
  25.     xmlHttp.open("POST", url, false);
  26.  
  27.     xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  28.     xmlHttp.setRequestHeader("Content-length", data.length);
  29.     xmlHttp.setRequestHeader("Connection", "close");
  30.  
  31.     xmlHttp.send(data);
  32. }
  33.  
  34. function updatePhoto() {
  35.     if (xmlHttp.readyState == 4) {
  36.         document.getElementById('photoBlock').innerHTML = "<img src='images/" + xmlHttp.responseText+ "' />";
  37.     }
  38. }
  39.  
  40. function getPhotoCount() {
  41.     if (xmlHttp.readyState == 4) {
  42.         photoCount = xmlHttp.responseText;
  43.     }
  44. }
The php file just returns the image location within the server. There's a <span> tag with id 'photoBlock' in the main html webpage.
Sep 12 '09 #1
1 2182
acoder
16,027 Expert Mod 8TB
You'll probably need to cache the images. If you already know the images that could be displayed, you could perhaps load them before they're required.
Sep 14 '09 #2

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

Similar topics

2
by: christopher.secord | last post by:
I would like have a little "loading..." tab not unlike the one that gmail uses and I would like to display that tab while an ajax call is made. The javascript to display the tab works. The...
8
by: DartmanX | last post by:
Hi, Looking for recommendations for a decent API for AJAX work. I need it to be somewhat documented so I can figure out how to actually use it. My most critical need right now is clean code...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
7
by: mitchell | last post by:
hi i m using IE 6.0. i want to refresh just the captcha part when the user clicks on an image. i searched for articles on it and got a fairly good understanding of it. but i m still unable to...
7
xNephilimx
by: xNephilimx | last post by:
lHi guys! I'm having a little problem that's getting on my nerves, I couldn't find a solution, I also tryed googling it and I found nothing... (my field of expertise is in AS 2 and 3, but I still...
3
by: hegdepras | last post by:
Hi, I need to load only the image in a JSP without refreshing the entire page. I have an action class which sends the stream of the image and I call this action class from 'src' of <img> tag in...
1
by: vjayis | last post by:
Hi I hav a page in which datas are displayed intially from the database. And using a link i m retriving datas from another page using ajax., it takes time and user might think tht nothing...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
6
by: ghjk | last post by:
I store images using one of my web pages. Next I want to load image from the db and pass the value to ajax page. Other values got correctly. But didn't get image.This is my code. php page. When...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.