AJAX -> storing result in variable using callback (undefined)

AJAX -> storing result in variable using callback (undefined)

I have a question to a very common problem. Probably dozens of question have been asked with regard to this. But unfortunately, I am not able to solve my problem anyway. Maybe you can help me! I have the following code:

 function get_network_from_database(callback) { $.ajax({ type: "POST", url: "load_network.php", data: "json", success: callback }); } function myCallback(result) { return result; } var matrix = get_network_from_database(myCallback);

Now, when I alert matrix then it says undefined but when I do alert(get_network_from_database(myCallback)); then it alerts the correct data.

Please could give me a hint what my problem is? All I want is to have the result in the matrix variable.

Thanks a lot in advance!