Loading Successive Select Boxes On Startup With Javascript
Solution 1:
So basically you are making two consecutive AJAX calls and try to tie the execution of second one to the result of the first one? This doesn't work that way, because first A letter in AJAX means Asynchronous, meaning "okay, guys, I'll go fetch that url but you can go on without me". So javascript fires first request and then goes further without waiting for it to return something.
If you want to run second request only after successful execution of the first one, then you'll need to use callbacks and onSuccess()
event.
To make it shorter, put the second call in the stateChanged()
function.
Solution 2:
You should write your javascript separate from your html. So your page startup event should be
window.onload = function() {
....
}
or withjquery:
$(function() {
....
});
So there you can put your other functions and code. And here would be a excellent to use JQuery. Look for example load method. It would propably solve your problems much faster than writing ajax from scratch.
Post a Comment for "Loading Successive Select Boxes On Startup With Javascript"