PDA

View Full Version : httpObject



SticksStones
Nov 24th, 2009, 09:11 PM
I'm having massive problems with a two-tier select menu working in tandem.
It works when it's being called from the root directory, but I keep getting 404's when called from sub directory (the extra directories come from search engine friendly URLs).
I'm pretty sure I'm one step away from getting it working, but my knowledge of javascript is poor and I can't figure out how to fix it.

Here's the js


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}

function showmodels(brand,filepath) {
//alert('brand=' + brand +' filepath=' + filepath + " doc=" + document.URL);
var strURL=filepath+"showmodels/"+brand;
var req = GetXmlHttpObject();

if (req) {

req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"

document.getElementById('ajaxModels').innerHTML=req.responseText;

}
}
req.open("GET", strURL, true);
req.send(null);
}
}

function showsubmit(brand,projector,filepath) {
//alert('brand=' + brand + ' \n projector=' + projector + " doc=" + document.URL);
var strURL=filepath+"showsubmit/"+brand+"/"+projector;
var req2 = GetXmlHttpObject();

if (req2) {

req2.onreadystatechange = function() {
if (req2.readyState == 4) {
// only if "OK"
if (req2.status == 200) {
document.getElementById('ajaxSubmit').innerHTML=req2.responseText;
} else {
alert("(submit| There was a problem while using XMLHTTP:\n" + req2.statusText + "\n" + req2.status);
}
}
}
req2.open("GET", strURL, true);
req2.send(null);
}

}
When an option is selected in the 1st select box, the js function "showmodels" calls showmodels.php via .htaccess. - this (almost) always works fine.
When showmodels calls showsubmit.php it only works in the main directory. In a sub directory I get a 404 error.
"submit| There was a problem while using XMLHTTP:Not found 404".

I assume the problem is to do with the document object on this line "document.getElementById('ajaxSubmit')" - in that it's pointing at the wrong place, but I really don't know how to begin trying to fix it beond trial and error and I've ran out of meaningful attemps!

Please help!