Closed
Bug 1110880
Opened 11 years ago
Closed 9 years ago
global variable optTexts goes missing in function
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: jmichae3, Unassigned)
Details
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
Build ID: 20141125180439
Steps to reproduce:
http://jesusnjim.com/calculators/PSU-calculators/power-supply-load-calculator2.html#app on local test server, not internet
f12
f5
Actual results:
TypeError: optTexts is undefined power-supply-load-calculator2.html:593
TypeError: data.find is not a function power-supply-load-calculator2.html:540
jquery ajax .find method disappeared
optTexts global variable not visible within function I made, and this is not inside AJAX.
Expected results:
.find method should be there
optTexts should be there
Comment 1•11 years ago
|
||
optTexts is assigned on line 501 in the script.
But on line 457, before optTexts has ever been assigned, the page calls cascadeSelectFillcat which uses optTexts before it returns. So the optTexts thing is just a bug in the page.
I can't reproduce the data.find error, in either a nightly or Firefox 34.
| Reporter | ||
Comment 2•11 years ago
|
||
my bad.
| Reporter | ||
Comment 3•11 years ago
|
||
now try line 593. global variable still missing across XHR, of which I was assured jquery was OK at.
had this problem before where XHR made global vars disappear in callbacks & such.
| Reporter | ||
Comment 4•11 years ago
|
||
I mean try a breakpoint at line 593... sorry.
Comment 5•11 years ago
|
||
So optTexts['category'] is a 0-length array. Why exactly are you expecting it to be something else? You're doing an async XHR then trying to use optTexts before the XHR finishes.
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
| Reporter | ||
Comment 6•9 years ago
|
||
a callback on XHR should have access to global vars. period. they should not become undefined suddenly within the callback function.
| Reporter | ||
Comment 7•9 years ago
|
||
please check again. a jquery simple test woule be better since it has the same problem the last time I checked.
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Comment 8•9 years ago
|
||
> a callback on XHR should have access to global vars. period
It looks like this page has gotten changed since I last looked at it, but the new setup on the page is this:
var optTexts = [];
initOpts();
where initOpts sets optTexts['categories'] to an empty array. Fine. Then the script does:
cascadeSelectFillcat('category','category');
and if you look inside cascadeSelectFillcat, it does things in this order:
1) Start an async XHR to get some data.
2) Execute this statement:
if (optTexts['category'].length) {
setidinner('oo2',"["+optTexts['category'].length+":"+optTexts['category'].join(',')+"]");
} else {
alert("ERROR:AJAX variables did not transfer, AJAX unable to access global vars!");
}
This statement will run before the XHR completes, since the XHR is async. So at that point optTexts['category'] is still the empty array that was set up in initOpts and hence its length is 0.
This is still invalid. Please don't reopen this bug again; this isn't a remote "debug my JS for me" service...
That said, what you probably want to do is factor all the bits of cascadeSelectFillcat that come at the end out into a function and call it from the done() blocks of the relevant $.get() calls in the switch. That will call that function _after_ the data has been gotten and the optTexts has been modified accordingly.
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago → 9 years ago
Resolution: --- → INVALID
| Assignee | ||
Updated•7 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•