How to receive Angular data in a PHP (route) file

Asked

Viewed 206 times

1

0 vote against Accept Friend, now it worked, but I was left with a doubt... Regarding the accentuation, he is not accepting accentuation.

I’ve tried the forms below, but there was no way:

var config = { headers : { 'Content-Type': 'application/json;charset=iso-8859-1' } };

var config = { headers : { 'Content-Type': 'application/json;charset=utf-8' } };

  • Begins by studying xmlhttprequest, ajax, and the module $http angular. In your case you will need to use the $http module to send the data to the php URL/route that will process it.

  • Mine sends accentuated and everything. If you can send PHP so I can see how you’re getting it. But it should probably be some adjustment that should be done in PHP.

1 answer

1

The Angularjs is a client-side framework, and as you may know PHP is server-side, so this is not: $title = '{book.title}}'. You have to pass $http this value to PHP -> https://docs.angularjs.org/api/ng/service/$http. Here’s an example I did in an app:

$scope.salvar = function(lista)
{
    var config = {
        headers : {
            'Content-Type': 'application/json'
        }
    };

    var data = lista;

    $http.post( Url.link + 'adicionar', data, config).success(function(res){
        alert('Cadastrado com sucesso');
    });

    $scope.lista = { lis_nome: '', lis_cpf: '', lis_animal: '', lis_descricao: '' };
};

I collect information from a form and send it via $http.post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.