dimanche 24 juillet 2016

Posting data to PHP with angularjs

I have looked at other options for posting data to php using angular but haven't had any success. I have an object called "user" that I have logged in js and can see that it's being populated. I am doing the post like

$http.post("./api/register.php", user, config).then(function(response) {
                return response.data;
            });

with a config object that looks like

var config = {
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            }

I have done an echo of a "hello" string in the php and I am able to see that however when I try to echo one of my variables I am unable to. Right now my php looks like

<?php

  $postdata = file_get_contents("php://input");
  $request = json_decode($postdata);
  $email = $request->email;
  $pass = $request->firstName;
  echo $email;
?>

I have lots of angular experience however only using java spring.

Aucun commentaire:

Enregistrer un commentaire