Bolboa Bolboa - 1 year ago 77
AngularJS Question

response from POST request NULL angular/php

I have a relatively simple POST request in angular...

var data = $.param({
clientID: '329272'

var config = {
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
$'./server.php', data, config)
.success(function (data, status, headers, config) {
.error(function (data, status, header, config) {

And my php code that receives the data is the following...

$postdata = file_get_contents('php://input');
$request = json_decode($postdata);

header('Content-Type: application/json');
echo json_encode($request);

All I am doing is sending data, then sending it back in the response to check if it worked.

The connection is made, and console prints out a status of
, but when I
, I get a value of
. Why am I not able to receive the data?

Answer Source

$.param() does not encode into json so json_decode($postdata) parse on the server will fail.

This function is used internally to convert form element values into a serialized string representation

You can use JSON.stringify to serialize javascript objects into JSON.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download