javaScript and Ajax - IE7

R

rbrowning1958

Hello,

I found some JavaScript to do im,age slideshows without having to list
all the images in an array:

http://webmasters.ucdavis.edu/resources/js_slideshow.html

You populate an XML file with the names / descriptions of the images
and this code loads them and displays them autmotically. The code
looks very well written but it's complex and it's using Ajax to read
the XML_ file (I suppose). However, it works fine in FireFox 8 but not
in IE 7. Now I'm guessing at what some of this code does but I think
it boils down to this:

var url = source_xml;
var myAjax = new Ajax.Request(url, { method: 'get', onComplete:
preloadSlideshow });

source_xml is a param to the routine so must be the code that is
retrieving the XML file and I'm guessing onComplete function is being
called when it's finished. I think it's this bit of the code that's
not working.

Ajax is this:

var Ajax = {
getTransport: function() {
return Try.these(
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
function() {return new XMLHttpRequest()}
) || false;
},

Now I just read a bit about how ajax talks to things and I know it's
diffrent for diff. browsers so 'm guessing it's trying these in this
order. Can anyone have a guess at why this isn't working in IE 7?

Thanks

Ray
 
D

David Mark

Hello,

I found some JavaScript to do im,age slideshows without having to list
all the images in an array:

That's positive as all of the images should be in the document.
http://webmasters.ucdavis.edu/resources/js_slideshow.html

You populate an XML file with the names / descriptions of the images

That's worse than using an array.
and this code loads them and displays them autmotically. The code
looks very well written but it's complex and it's using Ajax to read

It's not. It uses Prototype. Adding 80K of poorly written script to
your page is not a good way to swap images.
the XML_ file (I suppose). However, it works fine in FireFox 8 but not
in IE 7. Now I'm guessing at what some of this code does but I think
it boils down to this:

var url = source_xml;
var myAjax = new Ajax.Request(url, { method: 'get', onComplete:
preloadSlideshow });

source_xml is a param to the routine so must be the code that is
retrieving the XML file and I'm guessing onComplete function is being
called when it's finished. I think it's this bit of the code that's
not working.

Ajax is this:

var Ajax = {
getTransport: function() {
return Try.these(
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
function() {return new XMLHttpRequest()}
) || false;
},

That's a laugh. Is that in the slide show code itself? Prototype has
an Ajax wrapper. Wherever it came from, it is the wrong answer. See
a recent thread on this subject.
Now I just read a bit about how ajax talks to things and I know it's
diffrent for diff. browsers so 'm guessing it's trying these in this
order. Can anyone have a guess at why this isn't working in IE 7?

Hard to say without seeing the code behind this syntactic sugar. You
might ask the author of the script and they will likely have to ask in
a Prototype group. Maybe the developers will figure it out and post a
ticket. It may eventually get patched. Unforunately, most patches to
these sorts of libraries involve browser sniffing and so are virtually
guaranteed to break in the future. Perhaps you should try a different
slide show script.
 
R

rbrowning1958

That's positive as all of the images should be in the document.





That's worse than using an array.


It's not.  It uses Prototype.  Adding 80K of poorly written script to
your page is not a good way to swap images.










That's a laugh.  Is that in the slide show code itself?  Prototype has
an Ajax wrapper.  Wherever it came from, it is the wrong answer.  See
a recent thread on this subject.


Hard to say without seeing the code behind this syntactic sugar.  You
might ask the author of the script and they will likely have to ask in
a Prototype group.  Maybe the developers will figure it out and post a
ticket.  It may eventually get patched.  Unforunately, most patches to
these sorts of libraries involve browser sniffing and so are virtually
guaranteed to break in the future.  Perhaps you should try a different
slide show script.- Hide quoted text -

- Show quoted text -

Hello,

Trying to understand your comments. Why do u think it's prererable to
have the images in a javascript array? I'm thinking the opposite cos
if it's in XML I (or someone else) can change the XML without changing
the code. Obviously you know something I don't but I think I should
know...

Had to read up on prototype- is new to me. From what I gather it's
some code someone has written in javaScript which includes some
wrappers around Ajax calls, among other things. I'm getting the
impression you don't like it very much....R u saying it's a lot of
overhead I don't need"

I'm new to JavaScript - isn't here jsut some way I can read the files
in the directories or is this a security restriction?

I await your elightenment and thanks for your reply,

Ray
 
R

rbrowning1958

rbrowning1958took the time to say:










Ray,
The problem is IE7 uses a different DLL for xmlhttp in IE7. This block
will cover you in both IE6 and 7 for creating one.

var xmlhttp = null;
try {
     xmlhttp = new XMLHttpRequest();
   } catch (e) {
     try {
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (E) {
       xmlhttp = null;
     }
   }

return xmlhttp;

Then, to read the file you have on your domain, you could send off a
simple request to it:

xmlhttp.open("GET", 'url_to_page_on_your_server');
xmlhttp.onreadystatechange =
   function() {
     if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
       var pagedata = conn.responseText;
       // YOUR CODE FOR PAGE DATA
     }
   };
xmlhttp.send(null);

Hope this helps!

~A!- Hide quoted text -

- Show quoted text -

Hello,

Thanks for taking the time to post that. I've tried implementing what
you said but am unsure about one detail. The original code which used
that prototype stuff had this:

var myAjax = new Ajax.Request(url, { method: 'get', onComplete:
preloadSlideshow });

I'm assumg this is reading the file specified by url, and saying when
that read is complete to run preloadSlideshow. So I want to do this
without all the prototype stuff and tried using your code. I have this
which I got from you:

var xmlhttp = null;
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (E)
{
xmlhttp = null;
}
}

Then:

xmlhttp.open("GET", url);
xmlhttp.onreadystatechange =
function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var pagedata = conn.responseText;
// YOUR CODE FOR PAGE DATA
preloadSlideshow(xmlhttp); // tried conn here as well
}
};
xmlhttp.send(null);

I'm guessing youu're using a statechange event whereas the original
was using onComplete - but I assume your state and status checks end
up calling the code at the same time. All I want the code to do is
call preloadSlide after it has finished readign the file. What i'm
sure is causing me the problem is the parameter I pass to
preloadSlideshow. What is conn in your code? Is that some parameter to
the function I'm not seeing? In the original, I'm not sure what the
onComplete receieves as a parameter but it's accessing it like this:

function preloadSlideshow(originalRequest) {
var slideshow = originalRequest.responseXML;
var slides = slideshow.getElementsByTagName('slide');

blah blah...


By the way does that check in the try etc. work properly with other
browsers such as firefox?

Thanks a lot,

Cheers

Ray
 
R

rbrowning1958

rbrowning1958took the time to say:










Ray,
The problem is IE7 uses a different DLL for xmlhttp in IE7. This block
will cover you in both IE6 and 7 for creating one.

var xmlhttp = null;
try {
     xmlhttp = new XMLHttpRequest();
   } catch (e) {
     try {
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (E) {
       xmlhttp = null;
     }
   }

return xmlhttp;

Then, to read the file you have on your domain, you could send off a
simple request to it:

xmlhttp.open("GET", 'url_to_page_on_your_server');
xmlhttp.onreadystatechange =
   function() {
     if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
       var pagedata = conn.responseText;
       // YOUR CODE FOR PAGE DATA
     }
   };
xmlhttp.send(null);

Hope this helps!

~A!- Hide quoted text -

- Show quoted text -
Ignore the other message - I got past that - I pass the xmlhttp to my
function. Now here's what happens. Works in firefox. I had to take off
your status check of 200. However, on IE it never gets past this line:

xmlhttp.open("GET", url);
alert("after get");

never displays the alert. On both IE and FireFox this always displays
1:

try
{
xmlhttp = new XMLHttpRequest();
alert("1");
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
alert("2");
}
catch (E)
{
xmlhttp = null;
alert("3");
}
}
so I'm getting the XMLHttpRequest. I suspect this was the original
problem all along with IE - that the Get is not working for some
reason. A security settign I'm guessing?

Ta for you help so far,

Ray
 
M

My Pet Programmer

rbrowning1958 said:
Ignore the other message - I got past that - I pass the xmlhttp to my
function. Now here's what happens. Works in firefox. I had to take off
your status check of 200. However, on IE it never gets past this line:

xmlhttp.open("GET", url);
alert("after get");

never displays the alert. On both IE and FireFox this always displays
1:

try
{
xmlhttp = new XMLHttpRequest();
alert("1");
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
alert("2");
}
catch (E)
{
xmlhttp = null;
alert("3");
}
}
so I'm getting the XMLHttpRequest. I suspect this was the original
problem all along with IE - that the Get is not working for some
reason. A security settign I'm guessing?

Ta for you help so far,

Ray

Ok, you need to send the null value off as well.

xmlhttp.send(null);

You're not getting a return because you're not finishing the request.

And put the status check back in. You won't be able to alert a response
very well with a 404 in the status. :)

~A!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top