...

View Full Version : onreadystatechanged giving probs in FF



zenithwolf
09-11-2007, 11:07 PM
// send query to jsp for processing (with name of selected ingredient)
url = "get.jsp?selected_sub="
url += document.getElementById("sub_selectbox" +
qty_index).getElementsByTagName("option")[sub_index].text;
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = handleResponse;
xmlHttp.send(null);

// handle processed output
function handleResponse(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
// store processed response text
var getVal = xmlHttp.responseText;
if (((a.getElementsByTagName("input")[0].value)*1)>1) {
getVal *= a.getElementsByTagName("input")[0].value;
}
// display the value to user with multiplier to account for servings change(s)
if (multiplier!=0) {
document.getElementById("qty" + qty_index).innerHTML=(getVal*multiplier);
}
else {
document.getElementById("qty" + qty_index).innerHTML=(getVal);
}
}

I am trying to get values from a JSP and display to USER, JSP gets values from a database. First displays 3 choices to user, user selects one and the JSP Gives back a table and there are few select boxes in the data returned and the user selects whatever option he wants in this table. This all works when I have two choices in the FIRST select box I talked about even in FF. But when I added a 3rd option (and the data associated with it returns) the user tires to select an option, Firebug tells me the handleResponse is not defined. This code is for the the select boxes from my JSP. Again all of this works in IE. Ill post screens cuz I don't have any way to put it online.

Initial selection:

http://www.geocities.com/alvurnuscopernarus/initial.JPG


then the data with select boxes comes in and displayed:

http://www.geocities.com/alvurnuscopernarus/showeddata.JPG

then i select the other option in the select box (first one in the table) and error happens >< :

http://www.geocities.com/alvurnuscopernarus/error.JPG

rwedge
09-12-2007, 03:25 AM
Try putting open after readystatechange

xmlHttp.onreadystatechange = handleResponse;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);You will need to create a new instance of the XMLHttpRequest object for each request for IE, if you are not already.

zenithwolf
09-12-2007, 04:34 AM
nope still gives me that same error in firefox :(

rwedge
09-12-2007, 04:50 AM
Is handleResponse available to line 196?

With the requests being on different lines in firebug I assume you have more than one HttpRequest function.

zenithwolf
09-12-2007, 04:58 AM
more than 1 httpRequest function meaning the onreadystatechange ? cuz I have em in different functions and each one sends a new query...do i have to close when i use xmlHttp.open or something?

i said in my first post, the whole thing works in IE and it works if I have TWO choices in the first select box (see 1st screen shot) so I have no idea why this won't work!!

rwedge
09-12-2007, 06:33 AM
Maybe, for testing, a check just before the request
if (typeof xmlhttp != 'object') { alert('xmlHttp is not an object'); }
if (typeof handleResponse != 'function') { alert('handleResponse is not a function'); }

xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = handleResponse;
xmlHttp.send(null);
You could also check for errors in the response, but they should be visible in firebug
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
........
} else {
alert(xmlHttp.status + ' -- ' + xmlHttp.statusText);
}
}

zenithwolf
09-12-2007, 05:28 PM
did those checks and for some odd reason Firefox just CANNOT find that function, no matter what its named. It doesnt even enter the function just says its not even a function! still works in IE tho...

zenithwolf
09-12-2007, 07:25 PM
i got it working...I just removed the handle response as a different function and just put onreadystatechange as a function directly and now it works...


//if (typeof xmlHttp != 'object') { alert('xmlHttp is not an object'); }
//if (typeof handleResponse != 'function') { alert('handleResponse is not a function'); }

// send query to jsp for processing (with name of selected ingredient)
url = "get.jsp?selected_sub="
url += document.getElementById("sub_selectbox" + qty_index).getElementsByTagName("option")[sub_index].text;
xmlHttp.open("POST", url, true)
xmlHttp.onreadystatechange = function() {

// handle any errors that arise
var status = "N/A";
var statusText = "N/A";
try{ status = xmlHttp.status;}catch(e){}
try{ statusText = xmlHttp.statusText}catch(e){}
//handle processed output
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
// store processed response text
var getVal = xmlHttp.responseText;
if (((a.getElementsByTagName("input")[0].value)*1)>1) {
getVal *= a.getElementsByTagName("input")[0].value;
}
// display the value to user with multiplier to account for servings change(s)
if (multiplier!=0) {
document.getElementById("qty" + qty_index).innerHTML=(getVal*multiplier);
}
else {
document.getElementById("qty" + qty_index).innerHTML=(getVal);
}
}
};
xmlHttp.send(null);

A1ien51
09-13-2007, 08:16 PM
The problem was you need to define the function before you set its value since it is not global.

It is like you eating a sandwhich before you actually make it. You will not eat anything because it is not there yet.

Eirc

zenithwolf
09-14-2007, 04:17 AM
The problem was you need to define the function before you set its value since it is not global.

It is like you eating a sandwhich before you actually make it. You will not eat anything because it is not there yet.

Eirc

True, but it works everywhere else and it occurs for a certain amount of entries only...

jameslove
09-14-2007, 10:18 PM
Sometimes odd coding will work but inconsistently. Just cause something worked, does not mean it is correct. In other cases, it will crap out.

zenithwolf
09-15-2007, 05:32 AM
hmm odd coding eh? I just adopted what I saw in a tutorial :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum