Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Crossbrowser Ajax - PRB: .responseText

0 views
Skip to first unread message

par7133

unread,
Aug 27, 2008, 10:49:11 AM8/27/08
to
Hi,
Yea, XMLHttpRequest give out a crossbrowser problem managing the
status change of the connection.

Here the solution:

var xmlhttp;
xmlhttp=null;

xmlhttp=new XMLHttpRequest();

if (xmlhttp!=null)
{
if (document.all) {
//THE PROBLEM

xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,false);
xmlhttp.send(null);

function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
response = xmlhttp.responseText;
}
else
{
// Problem retrieving data
}
}
}

if (response!="") {
// JSON code to manage the response

}

} else {

xmlhttp.open("GET",url);
xmlhttp.send(null);
xmlhttp.onreadystatechange=function ()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
response = xmlhttp.responseText;

if (response!="") {
// JSON code to manage the response
}

}
else
{
// Problem retrieving data
}
}
}

}

}
else
{
// Problem with XMLHTTP
}


Hope this helps,

http://blog.daniele.bonini.name/index.php/2008/08/27/crossbrowser-ajax-prb-responsetext/

Gregor Kofler

unread,
Aug 27, 2008, 3:13:38 PM8/27/08
to
par7133 meinte:

> Hi,
> Yea, XMLHttpRequest give out a crossbrowser problem managing the
> status change of the connection.
>
> Here the solution:

["solution" aka crap snipped]

> Hope this helps,

Whom? Why? And: No.

Gregor


--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum

Thomas 'PointedEars' Lahn

unread,
Aug 27, 2008, 5:09:01 PM8/27/08
to
par7133 wrote:
> Yea, XMLHttpRequest give out a crossbrowser problem managing the
> status change of the connection.

Utter nonsense. The problem with this code, which mislead you or its author
into using error-prone object inference[1], is that there is a function
declaration within a block statement which is no longer supported by
mozilla.org JavaScript[tm] as it is a proprietary feature (which is
supported by Microsoft JScript). The branching is unnecessary if you use a
function expression always:

xmlhttp.onreadystatechange = function() {
// ...
};

That is easier to see if you reduce the number of empty lines and employed
proper indentation. Besides, your code is still far from being
cross-browser or working at all (the correct order is: open,
onreadystatechange, send; and that is not the end of it). In fact, this
problem has already been solved, far better, years ago.


HTH

PointedEars
___________
[1] <http://PointedEars.de/scripts/test/whatami#inference>
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16

0 new messages