1

Hi i tried POST json data in two ways its response in null

    var jsonData = $scope.addedCat; 
    console.log(jsonData);
    var request = $http({
        method:"POST",
        url:base_url+"Category_controller/json_test",
        data: JSON.stringify(jsonData),
        dataType: "application/json"
    });
    request.success(
    function(response){
         console.log(response);
    });

var cat_j = $scope.addedCat;
var data = $.param({ json:JSON.stringify(cat_j)});
$http.post(base_url+"Category_controller/json_test/",data).success(function(data, status) {
      console.log(data);
      console.log(status);
    })
How we decode the json data in php. I tried like this in Codeignitor framework.

    $cjson = $this->input->post('jsonData');
    $cat_json = json_decode($cjson);
    echo json_encode($cat_json);
0

3 Answers 3

1

On your server php file , try that instead, and you get the parametes passed from client:

//get parameters 
$params = json_decode(file_get_contents('php://input'), true); //read values from angular directive
Sign up to request clarification or add additional context in comments.

Comments

0

Superglobal $_post only support application/x-www-form-urlencoded and multipart/form-data-encoded.

For application/json you should use php://input which can give you the raw bytes of the data. Here is a sample code of how to get the input data:

// get the raw POST data

$rawData = file_get_contents("php://input");

// this returns null if not valid json

print_r(json_decode($rawData));

Comments

0
$data = json_decode(file_get_contents('php://input'), true);

and do $data['jsonData'] now this $data['jsonData'] === $this->input->post('jsonData');

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.