1

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(response) {
    // this callback will be called asynchronously
    // when the response is available
  }, function(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

I guess what I am trying to do is see the JSON string being sent to the server.

2
  • 1
    It's unclear. What you want to say ? Commented Sep 3, 2015 at 5:02
  • Touche, is it more clear now? Commented Sep 3, 2015 at 5:14

2 Answers 2

2

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 network click 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

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

2 Comments

If you still unable to see let me know
Thank you, I didn't know about the feature in chrome. I can see all the data for any request being done.
0

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.
});

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.