Connecting Tech Pros Worldwide Forums | Help | Site Map

Ajax div inside a table tag doesn't work!

Newbie
 
Join Date: Nov 2008
Posts: 3
#1: Nov 19 '08
Hi Guys


I need some expert advice on Ajax.
I have some difficulties updating a <div> tag inside a table with Ajax.


My html looks like this:

------------------------

...
[HTML]<table>
<tr>
<td>
<img src="../photos/abc_thumb.jpg" onClick="Load_Full_Size('abc')" />

<div id="abc" ></div>

</td></tr>
</table>
[/HTML]...

------------------------
The content I want to add inside <div> tag is the following (extra) <img> tag:

[HTML]<img src="../photos/abc_full_size.jpg" />
[/HTML]

This will be done by a php script which is already tested & functioning.
------------------------
The Ajax for this task is like following:


Expand|Select|Wrap|Line Numbers
  1. var objXMLHttpReq1 = createXMLHttpReq();
  2. var urlPhotoPhp = "showphoto.php?photo=";
  3.  
  4.  
  5. function Load_Full_Size(strItemPhoto)
  6. {
  7.  
  8.     objXMLHttpReq1.open("GET", urlPhotoPhp + escape(strItemPhoto) , true);
  9.     objXMLHttpReq1.onreadystatechange = Response_Handler_Photo();
  10.                 objXMLHttpReq1.send(null);
  11.  
  12.  
  13. }
  14.  
  15.  
  16. function Response_Handler_Photo()
  17. {
  18.  
  19.     if (objXMLHttpReq1.readyState == 4)    
  20.                 {
  21.  
  22.                  document.getElementById(strItemPhoto).innerHTML = objXMLHttpReq1.responseText;
  23.     }
  24. }
  25.  
  26.  
  27. function createXMLHttpReq()
  28. {
  29.     var objXMLHttpReq;
  30.  
  31.     if (window.XMLHttpRequest)
  32.     {
  33.         // Other Browsers
  34.         //
  35.         objXMLHttpReq = new XMLHttpRequest();
  36.  
  37. }
  38.     else if (window.ActiveXObject)
  39.     {
  40.         // IE
  41.         //
  42.         objXMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  43.  
  44. }
  45.  
  46.     return objXMLHttpReq;
  47.  
  48. }
------------------------

Apparently, the whole thing works when <div> is outside the table, but I need the full size pic inside the table :/

Any ideas? Thanks.

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Nov 19 '08

re: Ajax div inside a table tag doesn't work!


What I noticed is that the variable is named objXMLHttpReq, but you're using objXMLHttpReq1 or is that a typo?
Newbie
 
Join Date: Nov 2008
Posts: 3
#3: Nov 19 '08

re: Ajax div inside a table tag doesn't work!


sorry that was a typo only here.. (this i had correct in my code). thx
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Nov 20 '08

re: Ajax div inside a table tag doesn't work!


Is it necessary to make an Ajax request if all you want to do is to display an image? You can just create an image object, set its src to the full image source and append it to the div, or even set the innerHTML property.
Reply


Similar JavaScript / Ajax / DHTML bytes