3

I am Having following lines of code in my project.

var app = angular.module('myApp', []);

app.controller('myctrl', function ($scope, $http) { 
    $http.post('temp2.php', { msg:'hello' })
    .then(function (response) {
        alert(response.data);
    }, function (response) {
          alert("error");
    });
});

I am accessing msg using $_POST on temp2.php page. But it is showing the following error undefined index msg. Please help me.

Erazihel
  • 7,295
  • 6
  • 30
  • 53
Ankit21ks
  • 468
  • 1
  • 7
  • 22

1 Answers1

2

There is nothing wrong with angular part . check your php file . You are sending your data as json and it can be get in server side using\

 php://input .

$_POST will work fine if you will send payload as query string . "msg=text";

For more info check this

Community
  • 1
  • 1
Anil Sharma
  • 2,952
  • 5
  • 29
  • 45