function that return a value from ajax call request [duplicate]

You need to register a callback function, something like this:

function test() {
    myFunction(function(d) {
        //processing the data
        console.log(d);
    });
}

function myFunction(callback) {
    var data;
    $.ajax({
        url: 'url',
        data: 'data to send',
        success: function (resp) {
            data = resp;
            callback(data);
        },
        error: function () {}
    }); // ajax asynchronus request 
    //the following line wouldn't work, since the function returns immediately
    //return data; // return data from the ajax request
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)