Skip to content Skip to sidebar Skip to footer

How To Get Json String From Angular $http Post Request

I am sending this POST, I want to see the string that get's sent in the request before I send it. Here's Plunker $http.post('/someUrl', {msg:'hello word!'}). then(function(respon

Solution 1:

if you are hitting the url with config option like this

var config = {
    headers: { 'Content-type': 'application/json' },
    'dataType': 'json'
 };
var data = {
    name: 'intekhab',
    age:26,
};
$http.post('/admin/header', data, config).then(function(response){
    console.log(response);
});

Then you can see the data what are send. Open your browser console and click network then under networkclick your url what you have hit And now see the look at Request Payload under header tab There your data will be revealing what you have send to server.

And if you are not using config option like this

var data = {
        name: 'intekhab',
        age:26,
    };
    $http.post('/admin/header', data).then(function(response){
        console.log(response);
    });

Then do the same as above only difference is where you have seen the data under Request Payload, now you will see the same data under Form Data

enter image description here

enter image description here

Solution 2:

From what I understand, I think you want different handlers if the request succeeds or fails. You can do it in this way:

$http.post('/someUrl', {msg:'hello word!'}).
  success(function(response) {
    // this callback will be called asynchronously// when it succeeds
  }).error(function(response) {
    // called asynchronously if an error occurs// or server returns response with an error status.
});

Post a Comment for "How To Get Json String From Angular $http Post Request"