In my angular application, I am trying to sent the data to php script and then return a callback.
Here is the angular code:
var data = { value: 'somestring' };
$http.post("post_backend.php", data).success(function(data, status) {
alert(data + status);
}).error(function(data, status) {
alert(data + status);
});
In my php code I have a simple calling back function:
if (isset($_POST['value'])) {
header('Content-Type: application/json');
echo json_encode('successful callback');
exit();
}
But when it executes, I get a success status in the alert message and nothing else. I dont get the data ('successful callback') and can't figure out for about a couple of hours, what is the problem?
if (isset($_POST['value']))
condition is never met. What if youecho($_POST)
? What does PHP receive?alert()
instead useconsole.log()
and open your dev tools in the browser, this should prevent debug data from being malformed. Also don't use the+
operator, instead use a comma to seperate the arguments like so:console.log(data, status)
. Make sure there are no error in your console and check the network tab to see if the request is firing correctly.What is the problem? How can I fix it?
Well that's what we're trying to find out here. Hence my question "What if youecho($_POST)
? What does PHP receive?" That would be helpful if you answered :)