Angular JS POST request not sending JSON data

前端 未结 7 1756
忘掉有多难
忘掉有多难 2020-12-01 10:30

I am trying to send an object as JSON to my webservice in Flask that is expecting JSON in the request data.

I have tested the service manually by sending JSON data a

7条回答
  •  长情又很酷
    2020-12-01 11:01

    If you are serializing your data object, it will not be a proper json object. Take what you have, and just wrap the data object in a JSON.stringify().

    $http({
        url: '/user_to_itsr',
        method: "POST",
        data: JSON.stringify({application:app, from:d1, to:d2}),
        headers: {'Content-Type': 'application/json'}
    }).success(function (data, status, headers, config) {
        $scope.users = data.users; // assign  $scope.persons here as promise is resolved here 
    }).error(function (data, status, headers, config) {
        $scope.status = status + ' ' + headers;
    });
    

提交回复
热议问题