How do I do a POST + Redirect with Angular?

0

Hello, I need to make a post for a page and redirect along with the post for when loading the page displaying the posted data.

The problem is that when I do the post it already brings me the RESPONSE with the loaded data and if I do the redirect I will be doing a GET.

Can you post and open the page on the same request?

var data = {
    'nomede' :'Paulo',
    'emailde':'[email protected]',
    'sobrenomede':'Sousa',
    'sapde':'19811',
    'nomepara':'João',
    'emailpara':'[email protected]'
}

$http({
    url: 'http://pagina.com',
    method: "POST",
    params: data
}).then(function (response) {
    console.log(response.data);
    $window.location.href = 'http://pagina.com';
},
function (response) { // optional
    // failed
});

I can easily do this with JQUERY

var form = '';
$.each(data, function (key, value) {
form += '<input type="hidden" name="' + key + '" value="' + value + '">';
});
$('<form action="' + url + '" method="POST">' + form + '</form>').appendTo('body').submit();
    
asked by anonymous 23.02.2018 / 14:07

0 answers