AJAX and IE problem

Discussion in 'Javascript' started by will.hc.barker@gmail.com, Oct 17, 2006.

  1. Guest

    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').firstChild.data;
    num = response.getElementsByTagName('num').firstChild.data;
    idtofind = "commentcount" + id;
    newhtml = " (" + num + ")";

    document.getElementById(idtofind).innerHTML=newhtml;
    }

    }
    }
    , Oct 17, 2006
    #1
    1. Advertising

  2. Guest

    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??

    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').firstChild.data;
    > num = response.getElementsByTagName('num').firstChild.data;
    > idtofind = "commentcount" + id;
    > newhtml = " (" + num + ")";
    >
    > document.getElementById(idtofind).innerHTML=newhtml;
    > }
    >
    > }
    > }
    , Oct 17, 2006
    #2
    1. Advertising

  3. Hi,

    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
    Laurent Bugnion, Oct 18, 2006
    #3
  4. Dag Sunde Guest

    "Laurent Bugnion" <> skrev i melding
    news:45366ccf$...
    > Hi,
    >
    > 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.
    Dag Sunde, Oct 18, 2006
    #4
  5. Hi,

    Dag Sunde wrote:
    > "Laurent Bugnion" <> skrev i melding
    > news:45366ccf$...


    >> 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
    Laurent Bugnion, Oct 20, 2006
    #5
  6. VK Guest

    > 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.
    VK, Oct 20, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    20
    Views:
    1,875
    d1srupt3r
    Mar 31, 2008
  2. darrel

    beginner AJAX questions (AJAX.net)

    darrel, Apr 27, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    2,422
    Flinky Wisty Pomm
    Apr 28, 2006
  3. minnie
    Replies:
    1
    Views:
    670
    Andrew Thompson
    Dec 13, 2006
  4. Nathan Sokalski
    Replies:
    2
    Views:
    462
    Nathan Sokalski
    Jun 2, 2007
  5. =?Utf-8?B?VG9u?=
    Replies:
    2
    Views:
    533
    =?Utf-8?B?VG9u?=
    Jun 22, 2007
Loading...

Share This Page