469,927 Members | 1,947 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

AJAX and IE problem

Am trying to set up a very simple AJAX script for my website. The
javascript i have in an external file which reads as below.

This works perfectly in firefox but IE doesn't display anything at all.
No error messages, just a blank IE window. If you look at the IE source
this html is all there it just won't show it!

Any ideas

// JavaScript Document

function GetXmlHttpObject(handler)
{
var objXMLHttp=null;
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return objXMLHttp;
}
function getcounts(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="cgi-bin/countcomments.pl?blog_ids="
url=url+str
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
response = xmlHttp.responseXML.documentElement;
counts = response.getElementsByTagName('count');
for (i=0;i<=counts.length;i++)
{
id = response.getElementsByTagName('id')[i].firstChild.data;
num = response.getElementsByTagName('num')[i].firstChild.data;
idtofind = "commentcount" + id;
newhtml = " (" + num + ")";

document.getElementById(idtofind).innerHTML=newhtm l;
}

}
}

Oct 17 '06 #1
5 2579
Have half solved my problem. If i embed the javascript into the page it
works correctly.

Does IE have some security requirement about where external js files
are or something??

wi************@gmail.com wrote:
Am trying to set up a very simple AJAX script for my website. The
javascript i have in an external file which reads as below.

This works perfectly in firefox but IE doesn't display anything at all.
No error messages, just a blank IE window. If you look at the IE source
this html is all there it just won't show it!

Any ideas

// JavaScript Document

function GetXmlHttpObject(handler)
{
var objXMLHttp=null;
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return objXMLHttp;
}
function getcounts(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="cgi-bin/countcomments.pl?blog_ids="
url=url+str
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
response = xmlHttp.responseXML.documentElement;
counts = response.getElementsByTagName('count');
for (i=0;i<=counts.length;i++)
{
id = response.getElementsByTagName('id')[i].firstChild.data;
num = response.getElementsByTagName('num')[i].firstChild.data;
idtofind = "commentcount" + id;
newhtml = " (" + num + ")";

document.getElementById(idtofind).innerHTML=newhtm l;
}

}
}
Oct 17 '06 #2
Hi,

wi************@gmail.com wrote:
Have half solved my problem. If i embed the javascript into the page it
works correctly.

Does IE have some security requirement about where external js files
are or something??
No, it should work also with external JavaScript. Your code looks OK on
first sight, except for one thing: IIRC, IE doesn't accept relative URLs
for XmlHttpRequest calls. Try with an absolute URL, and if it works, use
the Location object to create the absolute URL from the relative one.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 18 '06 #3
"Laurent Bugnion" <ga*********@bluewin.chskrev i melding
news:45**********@news.bluewin.ch...
Hi,

wi************@gmail.com wrote:
>Have half solved my problem. If i embed the javascript into the page it
works correctly.

Does IE have some security requirement about where external js files
are or something??

No, it should work also with external JavaScript. Your code looks OK on
first sight, except for one thing: IIRC, IE doesn't accept relative URLs
for XmlHttpRequest calls. Try with an absolute URL, and if it works, use
the Location object to create the absolute URL from the relative one.
Are you telling me that this production code for IE doesn't work?

var xmlReq;

function sendBid() {

var url = "submitBid.asp";
if (window.XMLHttpRequest) {
xmlReq = new XMLHttpRequest();
}
else {
xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
}

var buffer = "";
//filling buffer here...
...

xmlReq.open("POST", url, true);
xmlReq.onreadystatechange = xmlSendBidCallback;
xmlReq.setRequestHeader( "Content-Type",
"application/x-www-form-urlencoded");
xmlReq.send("bidData=" + escape(buffer));
}

Well, the url variable above points to a page _relative_ to the current
page,
and this piece of code have been working without a glitch for the last
12 months...

--
Dag.
Oct 18 '06 #4
Hi,

Dag Sunde wrote:
"Laurent Bugnion" <ga*********@bluewin.chskrev i melding
news:45**********@news.bluewin.ch...
>No, it should work also with external JavaScript. Your code looks OK on
first sight, except for one thing: IIRC, IE doesn't accept relative URLs
for XmlHttpRequest calls. Try with an absolute URL, and if it works, use
the Location object to create the absolute URL from the relative one.

Are you telling me that this production code for IE doesn't work?
<snip>
Well, the url variable above points to a page _relative_ to the current
page,
and this piece of code have been working without a glitch for the last
12 months...
Yes. I said IIRC, which means If I Recall Correctly. Seems that I
didn't, Sorry about that ;-)

I know that we had problems with relative URLs and web services in IE. I
can't remember why. It was 3 years ago...

Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 20 '06 #5
VK
Yes. I said IIRC, which means If I Recall Correctly. Seems that I
didn't, Sorry about that ;-)

I know that we had problems with relative URLs and web services in IE. I
can't remember why. It was 3 years ago...
If we consider cross-domain lock for ajaxoids as a security mesure
(which is not and never was, but presuming if) then yes indeed
IXMLHTTPRequest / XMLHttpRequest do have this well-known "vulnerability
exploit" by allowing relative path in request. This is how one of the
most popular fixes ("mod_rewrite fix") is working: one calls say
"foobar.cgi" which is instructed in the server to be translated into
say "http://www.someAllAnotherServer.com/foobar.cgi".
Relative path was initially allowed on a number of send box
environments including for instance java.net.* package - and later
fixed to allow only fully-qualified path - for exactly the reason of
such exploits. So you may well be recalling a similar situation for
some another environment.
In application to ajaxoids the chances to have it "fixed" are very slim
though (too many of corporate solutions are running on it). And even if
"fixed" it adds nothing to the existing security, people will just
migrate on the second most popular (but more resource consuming)
alternative with server-side content grabbers. And the number zero :-)
stays as usual with iframe solutions.

Oct 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by bobzimuta | last post: by
31 posts views Thread by Tony | last post: by
5 posts views Thread by Martin | last post: by
3 posts views Thread by Alok yadav | last post: by
6 posts views Thread by =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post: by
3 posts views Thread by willl69 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.