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.

6
  • This does not look like an angular problem Commented Aug 13, 2015 at 13:03
  • Payload you are sending is not query string "msg=hello" . You can access {msg:'hello'} using php://input Commented Aug 13, 2015 at 13:06
  • What are the full contents of $_POST? Commented Aug 13, 2015 at 13:07
  • 1
    See this other stackoverflow question, already answered: stackoverflow.com/questions/15485354/… Commented Aug 13, 2015 at 13:31
  • @Creator: Thanks... Its working now Commented Aug 13, 2015 at 13:35

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.