Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Ajax request without XML

Reply
Thread Tools

Ajax request without XML

 
 
ircmaxell
Guest
Posts: n/a
 
      09-20-2007
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?

 
Reply With Quote
 
 
 
 
Jake Barnes
Guest
Posts: n/a
 
      09-20-2007
On Sep 20, 1:34 pm, ircmaxell <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
 
ircmaxell
Guest
Posts: n/a
 
      09-20-2007
On Sep 20, 1:49 pm, Jake Barnes <(E-Mail Removed)> wrote:
> On Sep 20, 1:34 pm, ircmaxell <(E-Mail Removed)> 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="Err or: 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);
}

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      09-20-2007
ircmaxell wrote:
> On Sep 20, 1:49 pm, Jake Barnes <(E-Mail Removed)> wrote:
>> On Sep 20, 1:34 pm, ircmaxell <(E-Mail Removed)> 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
 
Reply With Quote
 
ircmaxell
Guest
Posts: n/a
 
      09-21-2007
> 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>)...

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      09-21-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX Woes - XML HTTP Request not returning a value salvador Javascript 5 02-23-2007 01:32 AM
Deploying ASP.NET AJAX-Enabled Web site to host without AJAX insta =?Utf-8?B?QnJpYW4gRWR3YXJkcw==?= ASP .Net 2 02-21-2007 10:22 PM
AJAX IDE and AJAX TOOL--The Release of JoyiStar AJAX WebShop 3 Beta minnie Java 1 12-13-2006 06:29 AM
AJAX without XML psimakov@outplay.com Javascript 16 11-27-2005 08:22 PM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM



Advertisments