I’d like to fire a JavaScript function when AJAX returns the values of drop down items.
The scenario is:
function 1 fires -> ajax gets items from database -> the dropdown items are filles -> my javascript function is called.
Does any of you have idea how to make a handler for such event ?
As you’ve tagged the question with jQuery, I’ll show you a jQuery solution:
The various jQuery AJAX methods (
post,get,loadfor example) all provide a way to pass a callback as an argument. The callback is executed upon a successful response from the server. Inside that callback function you can execute whatever code you need to, to deal withdatawhich contains the response.If you’re not using jQuery, I’ll assume you already have an
XMLHttpRequestobject.XMLHttpRequesthas a property calledonreadystatechangeto which you can assign a function that runs when the state changes:The idea is the same as the jQuery method shown above.