JQuery ajax return value to other function

Hello I have next function, what always return null as result, but service calling to success branch with any error, I would like to fix it: 1. Remove async attribute, 2. Other function that make GetStore function call should process result of this function. How I can do this in correct way ? ()

Thanks.

 function GetStore() {
        $.ajax({
            url: serviceurl + 'GetSometing',
            type: 'POST',
            contentType: 'application/json',
            dataType: "json",
            async: false,
            success: function (result) {
                return result;
            },
            error: function (xhr, description, error) {
                return null;
            }
        });
    }

Answers


If you want to make it asynchronous you can't wait for it to return a value, you have to implement callback functions.

function GetStore(success, error) {
    $.ajax({
        url: serviceurl + 'GetSometing',
        type: 'POST',
        contentType: 'application/json',
        dataType: "json",
        success: success,
        error: error
    });
}

GetStore(function(result) {
    // successful result
}, function(xhr, description, error) {
    // an error occurred
});

Need Your Help

Is Changing My Home Directory Name Going to Mess Up Virtual Environments?

python django macos virtualenv

I'm looking to change my mac's home directory name. On the OS I'm on it seems this is the way to do it: https://discussions.apple.com/docs/DOC-3872

Manipulating text with symbols in PowerPoint using VBA

vba powerpoint powerpoint-vba

I am trying to use VBA to manipulate text in a PowerPoint.