Ajax request without XML

Discussion in 'Javascript' started by ircmaxell, Sep 20, 2007.

  1. ircmaxell

    ircmaxell Guest

    Here's my situation. I use "versioned" xml files to communicate
    between my server and my clients. When I say versioned, I increment a
    "version" value within the xml document upon each change (so if the
    versions are the same, the file is the same). Now, to reduce
    bandwidth and server load, I want the client to download this version
    first, test it, and then download the xml file ONLY if the version
    changes. I put the version into a simple flat file ("3324" is all
    that's in it). Then, using XMLHttpRequest.responseText, I check that
    number against the one in memory. It works great in IE, and works in
    FF, but in FF it throws a syntax error ("3324^"). Is there any way I
    can prevent this error, and still use this model?
    ircmaxell, Sep 20, 2007
    #1
    1. Advertising

  2. ircmaxell

    Jake Barnes Guest

    On Sep 20, 1:34 pm, ircmaxell <> wrote:
    > Here's my situation. I use "versioned" xml files to communicate
    > between my server and my clients. When I say versioned, I increment a
    > "version" value within the xml document upon each change (so if the
    > versions are the same, the file is the same). Now, to reduce
    > bandwidth and server load, I want the client to download this version
    > first, test it, and then download the xml file ONLY if the version
    > changes. I put the version into a simple flat file ("3324" is all
    > that's in it). Then, using XMLHttpRequest.responseText, I check that
    > number against the one in memory. It works great in IE, and works in
    > FF, but in FF it throws a syntax error ("3324^"). Is there any way I
    > can prevent this error, and still use this model?



    Can we see some code? Perhaps an URL? It's hard to give advice if you
    won't show any code.
    Jake Barnes, Sep 20, 2007
    #2
    1. Advertising

  3. ircmaxell

    ircmaxell Guest

    On Sep 20, 1:49 pm, Jake Barnes <> wrote:
    > On Sep 20, 1:34 pm, ircmaxell <> wrote:
    >
    > > Here's my situation. I use "versioned" xml files to communicate
    > > between my server and my clients. When I say versioned, I increment a
    > > "version" value within the xml document upon each change (so if the
    > > versions are the same, the file is the same). Now, to reduce
    > > bandwidth and server load, I want the client to download this version
    > > first, test it, and then download the xml file ONLY if the version
    > > changes. I put the version into a simple flat file ("3324" is all
    > > that's in it). Then, using XMLHttpRequest.responseText, I check that
    > > number against the one in memory. It works great in IE, and works in
    > > FF, but in FF it throws a syntax error ("3324^"). Is there any way I
    > > can prevent this error, and still use this model?

    >
    > Can we see some code? Perhaps an URL? It's hard to give advice if you
    > won't show any code.


    Well, the URL is not published yet (it's on a development server for
    now)... Here's the functions I am using... The Backend calls
    check_request() every x seconds (say 30 or 60)...

    var version;
    function check_request() {
    var req = null;
    if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    if (req.overrideMimeType) {
    req.overrideMimeType('text/xml');
    }
    } else if (window.ActiveXObject) {
    try {
    req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    req = new
    ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
    }
    }
    req.onreadystatechange = function() {
    if(req.readyState == 4) {
    if(req.status == 200) {
    var doc = req.responseText;
    //handle response
    //alert('Doc: ' + doc + ' - - ' +
    version);
    if(doc != version) {
    //alert("Reload!");
    request();
    }
    }
    }
    }
    stamp = new Date();
    var time = stamp.getTime();
    req.open("GET", "http://dataURL" + scope + ".data?time="+time,
    true);
    req.send(null);
    }
    function request() {
    var req = null;
    if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    if (req.overrideMimeType) {
    req.overrideMimeType('text/xml');
    }
    } else if (window.ActiveXObject) {
    try {
    req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    req = new
    ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
    }
    }
    req.onreadystatechange = function() {
    if(req.readyState == 4) {
    if(req.status == 200) {
    var doc = req.responseXML;
    var root =
    doc.getElementsByTagName('root')[0];
    version =
    root.getElementsByTagName('version')[0].firstChild.nodeValue;
    //Parse XML file here...
    } else {

    document.getElementById("messages").innerHTML="Error: returned status
    code " + req.status + " " + req.statusText;
    }
    }
    };
    stamp = new Date();
    var time = stamp.getTime();
    req.open("GET", "http://dataURL/" + scope + ".xml?time="+time,
    true);
    req.send(null);
    }
    ircmaxell, Sep 20, 2007
    #3
  4. ircmaxell wrote:
    > On Sep 20, 1:49 pm, Jake Barnes <> wrote:
    >> On Sep 20, 1:34 pm, ircmaxell <> wrote:
    >>> [Use XHR to determine whether XHR should be used]
    >>> I put the version into a simple flat file ("3324" is all
    >>> that's in it). Then, using XMLHttpRequest.responseText, I check that
    >>> number against the one in memory. It works great in IE, and works in
    >>> FF, but in FF it throws a syntax error ("3324^"). Is there any way I
    >>> can prevent this error, and still use this model?

    >> [...]

    >
    > [...] Here's the functions I am using... The Backend calls
    > check_request() every x seconds (say 30 or 60)...


    Your posted code does not show anything that would explain the
    aforementioned error message. You should post the *full* error
    message and explain how you obtained it.

    Firebug may help to see where the problem is, as it logs all XHRs.

    As for your code, it is certainly a good idea to do some refactoring.
    Common parts should be defined in a commonly used function, for example.


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
    Thomas 'PointedEars' Lahn, Sep 20, 2007
    #4
  5. ircmaxell

    ircmaxell Guest

    > Your posted code does not show anything that would explain the
    > aforementioned error message. You should post the *full* error
    > message and explain how you obtained it.
    >
    > Firebug may help to see where the problem is, as it logs all XHRs.
    >
    > As for your code, it is certainly a good idea to do some refactoring.
    > Common parts should be defined in a commonly used function, for example.
    >
    > PointedEars


    That's the thing, firebug does not show any error... All variables are
    populated properly. The error is comming in via FF's Error Console...
    Basically, like it was expecting open and close tags, but never saw
    them... It would be stupid to have to wrap 2 bytes of data in 7 bytes
    of tags (<v>43</v>)...
    ircmaxell, Sep 21, 2007
    #5
  6. ircmaxell wrote:
    >> Your posted code does not show anything that would explain the
    >> aforementioned error message. You should post the *full* error
    >> message and explain how you obtained it.
    >>
    >> Firebug may help to see where the problem is, as it logs all XHRs.
    >>
    >> As for your code, it is certainly a good idea to do some refactoring.
    >> Common parts should be defined in a commonly used function, for example.
    >> [...]


    http://netmeister.org/news/learn2quote.html

    > That's the thing, firebug does not show any error... All variables are
    > populated properly. The error


    Which is most certainly not only "3324^", now is it?

    > is comming in via FF's Error Console...


    I have never encountered a case where Firefox' Error Console shows an error
    message and Firebug's doesn't. Probably you have disabled the display of
    those error messages in Firebug. Check the Options menu in the Firebug
    pane/window. And Firebug certainly can show the request and response
    messages of the XHR.

    > Basically, like it was expecting open and close tags, but never saw
    > them... It would be stupid to have to wrap 2 bytes of data in 7 bytes
    > of tags (<v>43</v>)...


    It would appear that without seeing the code in action or at least the
    response message, one cannot tell what is going wrong.


    PointedEars
    Thomas 'PointedEars' Lahn, Sep 21, 2007
    #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. Brian Birtle
    Replies:
    2
    Views:
    2,015
    John Saunders
    Oct 16, 2003
  2. =?Utf-8?B?QnJpYW4gRWR3YXJkcw==?=

    Deploying ASP.NET AJAX-Enabled Web site to host without AJAX insta

    =?Utf-8?B?QnJpYW4gRWR3YXJkcw==?=, Feb 20, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    589
    Patrick
    Feb 21, 2007
  3. minnie
    Replies:
    1
    Views:
    683
    Andrew Thompson
    Dec 13, 2006
  4. AJAX without XML

    , Nov 21, 2005, in forum: Javascript
    Replies:
    16
    Views:
    155
    Randy Webb
    Nov 27, 2005
  5. salvador
    Replies:
    5
    Views:
    136
    salvador
    Feb 23, 2007
Loading...

Share This Page