XMLHttp in FF - can't get a response

webmasterbeta

New Member
Ok - pretty simple ajax implementation, code is below. Works great in IE, bombs in FF.

Here's the main page in question: <!-- m --><a class="postlink" href="http://www.blockrocker.com/index2.php">http://www.blockrocker.com/index2.php</a><!-- m -->

- Tried using GMap AJAX framework - no dice.
- XML being returned from PHP is well-formed, and has proper mime types - check out <!-- m --><a class="postlink" href="http://www.blockrocker.com/ajax_categories.php">http://www.blockrocker.com/ajax_categories.php</a><!-- m -->
- Tried different encoding types in the XML - no dice
- Tried the overridemimetype trick in javascript - no dice
- FF seems to skip from readyState 1 to rs 4 - what does this mean?
- Any attempt to access xmlhttp.status causes exception errors in the JS console
- have tried it with straight XML, tried it with text files, etc etc. Always works merrily in IE.

So - at this point, I'm stumped - WTF? I use really similar code all over the place on other projects, and it works great in all browsers. I posted this question to the Google Ajax World Group, and have gotten some code tweaks, but no answers yet. Anyone that can shed some light on this will get my eternal appreciation and credit on the site (<!-- m --><a class="postlink" href="http://www.blockrocker.com/">http://www.blockrocker.com/</a><!-- m -->).

I hate to start of my time on this forum with an appeal for help, but I'm stumped - your assistance is appreciated!

-Rod.

function createRequestObject() {
var ro;
if(window.XMLHttpRequest) {
ro = new XMLHttpRequest();
} else {
ro = new ActiveXObject("Microsoft.XMLHTTP");
}
return ro;
}

var xmlhttp = createRequestObject();
var isBusy = true;

function handleCategories() {
if(xmlhttp.readyState == 4){
isBusy = false;

document.getElementById("search_results").innerHTML = "<span class='title_orange'>Almost there...</span>";
var categories = xmlhttp.responseXML.getElementsByTagName("category");
var output = "<table cellspacing=\"1\" cellpadding=\"3\" class=\"text\" width=\"100%\">";
rowcounter = 0;
for (i = 0; i < categories.length; i++) {
category = categories.item(i);
if (category.getAttribute("count") > 0) {
if (rowcounter == 0) { output = output + "<tr>"; }
output = output + "<td>" + category.getAttribute("name") + " [" + category.getAttribute("count") + "]</td>";
if (rowcounter == 1) { output = output + "</tr>"; }
if (rowcounter == 1) { rowcounter = 0; } else { rowcounter++; }
}
}
output = output + "</table>";
document.getElementById("search_results").innerHTML = output;

} else {
document.getElementById("search_results").innerHTML = "<span class='title_orange'>Searching... " + xmlhttp.readyState + "</span>";
}
}

function ajax_load(map) {
map.clearOverlays();
if (isBusy) { xmlhttp.abort(); }
isBusy = true;
var center = map.getCenterLatLng();
var bounds = map.getBoundsLatLng();
var width = bounds.maxX - bounds.minX;
var height = bounds.maxY - bounds.minY;
var request_string = "/ajax_categories.php?srch_height=" + height + "&srch_width=" + width + "&srch_latt=" + center.y + "&srch_longt=" + center.x;
xmlhttp.open("post", request_string, true);
xmlhttp.onreadystatechange = handleCategories;
xmlhttp.send(null);
}

function showMap() {
var map = new GMap(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());

GEvent.addListener(map, 'moveend', function() {
result = ajax_load(map);
});
GEvent.addListener(map, 'click', function(overlay, point) {
result = ajax_load(map);
});
GEvent.addListener(map, 'zoom', function(oldZoomLevel, newZoomLevel) {
result = ajax_load(map);
});

var point = new GPoint(srch_longt, srch_latt);
map.centerAndZoom(point, srch_zoom);
}
 
Back
Top