Click to See Complete Forum and Search --> : XMLHttp in FF - can't get a response


rodedwards
03-08-2006, 04:28 PM
Ok - pretty simple ajax implementation, code is below. Works great in IE, bombs in FF.

Here's the main page in question: http://www.blockrocker.com/index2.php

- Tried using GMap AJAX framework - no dice.
- XML being returned from PHP is well-formed, and has proper mime types - check out http://www.blockrocker.com/ajax_categories.php
- 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 (http://www.blockrocker.com/).

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

drhowarddrfine
03-08-2006, 04:40 PM
Maybe I missed it but to use XMLHttpRequest, you must test for both Microsofts way and everyone elses. It looks like you only use the MS way. Unless someone comes here with the exact code, I'll look it up or you can google for it.

Try this. (http://swik.net/Ajax/How+to+use+XMLHttpRequest)

rodedwards
03-08-2006, 04:42 PM
Hey Drhoward - thanks for chipping in. Take a look at my first function, however:

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

I am able to instantiate the request object, I just can't get anything useful out of it after it hits readystate 4.

drhowarddrfine
03-08-2006, 04:43 PM
Look here and see if this helps. (http://swik.net/Ajax/How+to+use+XMLHttpRequest)

rodedwards
03-08-2006, 04:49 PM
Hmmm... nope. My code follows the swik code in pretty much every way. Given that I use similar code on other projects and servers, I'm wondering if the server this site is on could be mangling the response somehow.

drhowarddrfine
03-08-2006, 05:13 PM
Well, yeah, it was right there in front of me and I didn't see it. I'm wondering if missing a doctype has anything to do with it. Haven't had a chance to work with this in quite a while so I won't be much use.