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/
["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
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