My function is very simple, and based on what I found here. Yet I cant seem to make it work, whats wrong?
function ajax(url) {
    var result;
    $.ajax({
        url: url,
        success: function(data) {
            result = data;
            //$('#test').html(data);
            }
        });
    return result;
    }
The function is getting the data, for if I uncomment the commented code and call it, then the data is shown inside the #test element. However, if I write
var test = ajax('my-url.php');
$('#test').html(test);
then it doesnt work. My guess is that for some reason, the data in "data" is not being stored in the variable "result". But I cant figure out why, nor how to solve it. Any help is appreciated.
 
     
     
    