I am working on a website using JQuery to display HTML returned from an AJAX call. Upon clicking a button, the following JS function is called:
function example(...) {
get_ajax_and_display(...);
show_hidden_div(...);
}
The first function get_ajax_and_display() makes an ajax call, and on success, calls $("#ex_div").html(ajax_response) to set the innerHTML of ex_div to whatever was returned from the ajax call. In particular, that returned html contains a <span id='ex_span' style="display: none">.
The second function show_hidden_div() calls $("#ex_span").show() in order to display that span.
However, the second function call fails, as $("#ex_span") seems to be undefined, even though the first function already created it.
Does the .html(ajax_response) not actually get set until the example(...) function returns?
I call the 2 inner functions separately in other parts of my code and they work fine on their own.
Why can't I call them like this?
$.post()function. Required a bit of a refactor, but the result is much better than using the deprecatedasyncparameter.