Ajax request without XML

I

ircmaxell

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

Jake Barnes

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.
 
I

ircmaxell

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);
}
 
T

Thomas 'PointedEars' Lahn

ircmaxell said:
[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
 
I

ircmaxell

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>)...
 
T

Thomas 'PointedEars' Lahn

ircmaxell said:
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
 

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

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top