I'm trying to write a Javascript/jQuery function that loads another page from a server, parses it (to determine its parent page), and returns that value.
My function currently looks like this:
function getParent(pageNo) {
$.get( [page_reference] , function(loaded_stuff) {
[process to parse loaded_stuff to determine return_value]
alert (return_value); // displays the value I want
});
}
But I can't figure out how to capture the return value.
If I put a return
statement directly after the alert()
, I'm returning to some JQuery function, not the function I'm calling from. My function receives undefined
.
If I put a return
statement directly before the final curly bracket, then Javascript will execute it before it finishes the asynchronous AJAX bit. My function receives the initial value of return_value
.
I'm sure there must be a simple answer to this, but I've been unable to find it. I can't figure out how to make the functions execute sequentially. Can you help me?