I made a function for managing data sending to server side. I want to return response of $http when it success.
My controller: (When I call the function)
var myResponse = sendData(inputValueArray, url, onSuc, onErr, $http);
// Nothing happen here:
alert(myResponse);
My function for sending data:
function sendData(inputArray, url, onSuccess, onErr, $http) {
var serverResponse = "";
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$http({
        method: 'POST',
        url: url,
        data: {
          myData: inputArray
        },
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    })
.success(function(response) {
    if (response.res == true) {
        onSuccess();
        serverResponse = response;
    }
    else {
        onErr();
    }
})
.error(function(data, status, headers, config) {
    onErr();
});
return serverResponse;
}
 
    