1

I am so beginner programming with Angularjs and I want to make post request to my server. On the server side I'am waiting data with key value pair. But when I try to post with the example code below I sent data in json so ı can't parse it on the server side. I googled this issue but i couldn't find the answer but I'm pretty sure there is a way. I hope somebody will tell this.

$scope.postData = function postData(data) {
        $http.post('apiurl/functionName', {post_data:data}).success(
                alert("Success"));
    };
  • What is your server-side language? – fracz May 23 '15 at 10:03
  • possible duplicate of [AngularJS - Any way for $http.post to send request parameters instead of JSON?](http://stackoverflow.com/questions/12190166/angularjs-any-way-for-http-post-to-send-request-parameters-instead-of-json) – fracz May 23 '15 at 10:03
  • I use php on the server side on the client side i'am sending json data with key value and on the server side i'am decoding and parsing it. –  May 23 '15 at 10:06

1 Answers1

2
var request = {};
request.method = 'POST';
request.data = JSON.stringify(JSONdata);
request.url = url;
request.timeout = 1000 * 60;

var promise = $http(request);

promise.success(function(data, status, header, config) {
    //  successCallback;
});

promise.error(function(data, status, header, config) {
    // errorCallback
});
Hardy
  • 542
  • 4
  • 10
  • hi Hardy, thak you for your response. i got posting data and parse it successfully with your code. but i got all values as '0'. do you have an idea about this situation? –  May 23 '15 at 11:28