4

I want to send a post request by angular. My problem is angular actually send a get request instead of a post request. My angular request is here:

$http({
        method: 'POST',
        url: pages_url,
        params: {
            'page': $scope.current_page_id,
            'news': JSON.stringify(news),
            'method': 'POST'
        }
    }).then(function (response) {
        alert(JSON.stringify(response));
    });

When i debug the request with network tab of browser, i see the parameter of the request in my server url. what should i do?

2
  • What do you see in the network tab ? Can you post that here ? Commented Jan 10, 2017 at 17:44
  • @suzo I was see this: my server IP/Newspaper/Edit?method=POST&news=[{"body":"","editor":"editable1","title":""},{"body":"","editor":"editable2","title":""}]&page=5872525f3c6130641da66e56 Commented Jan 10, 2017 at 17:55

2 Answers 2

2

I would write it like this:

var req_body = {
    page: $scope.current_page_id,
    news: JSON.stringify(news),
    method: 'POST' // <- is this really a parameter you want or do you misunderstood the post as a request?
};
$http.post(pages_url, req_body)
     .then(function (response) {
         alert(JSON.stringify(response));
     });
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

function yourFunction(param1, param2) { 
        return $http({ 
            method: 'POST', 
            url: yourUrl, 
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}, transformRequest: function(obj) { 
                var str = []; 
                for(var p in obj) 
                    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); 
                return str.join("&"); 
            }, 
            data: {username: param1, password: param2} 
            })
           .then(function(response) {
                return response;
            });
    }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.