By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Ajax Script - works in Firefox, not in IE6

P: 32
I'm testing an ajax page - this works fine in Firefox:
http://jimpix.co.uk/clients/a/ecards/defaultx.asp

Click on any of the links on the right under the 'occassions' or 'others' headings, in Firefox, and thumbnails appear based on what you clicked on.

Do the same in IE6, and it returns an error:

Line: 71
Char: 9
Error: Unknown runtime error


This relates to this line:

Expand|Select|Wrap|Line Numbers
  1. <p class="ctr"><span id="my_photo_id_label"></span></p>
The error happens as soon as the page is loaded, before I even click a link.

This is the javascript on the page:

Expand|Select|Wrap|Line Numbers
  1. function addLoadEvent(func) {
  2.     var oldonload = window.onload;
  3.     if (typeof window.onload != 'function') {
  4.         window.onload = func;
  5.     } else {
  6.         window.onload = function() {
  7.             if (oldonload) {
  8.                 oldonload();
  9.             }
  10.             func();
  11.         }
  12.     }
  13. }
  14.  
  15. function GetXmlHttpObject() {
  16.   var xmlhttp;
  17.   if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
  18.     xmlhttp = new XMLHttpRequest();
  19.     //if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/xml');
  20.   } else if (window.ActiveXObject) { // IE
  21.       try {
  22.         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  23.       } catch (e) {
  24.           try {
  25.             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  26.           } catch (e) {}
  27.       }
  28.   }
  29.   if (!xmlhttp) {
  30.     alert('Cannot create an XMLHTTP instance');
  31.     return false;
  32.   }
  33.   return xmlhttp;
  34. }
  35.  
  36. var ec = GetXmlHttpObject();
  37.  
  38. function sendMyPhotoRequest(id) {
  39.     ec.open('get', '../ajax/ajax-ec.asp?id=' + encodeURIComponent(id));
  40.     ec.onreadystatechange = handleMyPhotoResponse;
  41.     ec.send(null);
  42. }
  43.  
  44. function handleMyPhotoResponse() {
  45.     // If everything is okay:
  46.     if(ec.readyState == 4){
  47.         // Assign the returned value to the document object.
  48.         document.getElementById('my_photo_id_label').innerHTML = ec.responseText;
  49.     }
  50. }
  51.  
  52. addLoadEvent(function() {
  53.     sendMyPhotoRequest(44);
  54. })
The plan was to click a hyperlink on the right, and then send a variable to the 'ajax-ec.asp' page, via this syntax:

Expand|Select|Wrap|Line Numbers
  1. <li><a href= "#pop" onclick="sendMyPhotoRequest(45);">Various</a></li>
Not sure why it would work for Firefox, but not IE6.

I tested on another page:
http://jimpix.co.uk/clients/a/ecards/default-photo.asp

And this works in IE6, even though the Javascript is v. similar.

But instead of passing the variable as a number as above, the hyperlink is as follows:

Expand|Select|Wrap|Line Numbers
  1. <a title="" href="#pc" onclick="sendPhotoRequest(next_photo());">Next</a>
And the function initialising the page is:

Expand|Select|Wrap|Line Numbers
  1. addLoadEvent(function() {
  2.     sendPhotoRequest(MyPhotoVar);
  3. })
Where MyPhotoVar is initialised as:

Expand|Select|Wrap|Line Numbers
  1. var MyPhotoVar = 0;
Is that the problem - that I can't send numbers via the functions, but need to use a variable instead?

I'm sorry for:

1. Going on for so long
2. Not knowing what I'm doing
3. Talking a load of rubbish

Thanks
Sep 26 '08 #1
Share this Question
Share on Google+
2 Replies


P: 32
Fixed it. Sorry to waste anyones time.
Sep 27 '08 #2

Markus
Expert 5K+
P: 6,050
Fixed it. Sorry to waste anyones time.
Care to post how you solved this problem? It may help others.

Cheers.
Sep 27 '08 #3

Post your reply

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