简体   繁体   English

$ http POST没有返回正确的响应

[英]$http POST not returning correct response

The issue I'm having is that $http POST is not returning the correct response. 我遇到的问题是$ http POST未返回正确的响应。 The data I require is stored under config instead of data 我需要的数据存储在config下而不是数据下

The Http POST request: Http POST请求:

for (var i = 0; i < filmService.filmData.length; i++) {
      filmData.push({
        title     :    filmService.filmData[i].title,
        overview  :    filmService.filmData[i].info,
        poster    :    filmService.filmData[i].poster,
        genres    :    filmService.filmData[i].genres,
        release   :    filmService.filmData[i].release

      }); 
}
  var data = angular.toJson(filmData[0]);


     $http({
            method: 'POST',
            url:'/search',
            data: data,
            headers: {
              'Content-Type': 'application/json;charset=utf-8'
          },
        }).then(function successCallback(response) {
            console.log(response); //response received
    });

The response I got in the console - highlighted in RED is the data I need: 我在控制台中得到的响应 -以红色突出显示的是我需要的数据:

RED中突出显示的部分是我需要的数据,而CONFIG中则是它。

Do this and you should get what you want: 这样做,您应该得到想要的:

  $http({
        method: 'POST',
        url:'/search',
        data: data,
        headers: {
          'Content-Type': 'application/json;charset=utf-8'
      },
    }).then(function successCallback(response) {
        var data = response.data
        console.log(data); //response received
});

Inside your .then function return the config.data. 在您的.then函数内部.then返回config.data。

The result will be like this 结果将是这样

$http({
        method: 'POST',
        url:'/search',
        data: data,
        headers: {
          'Content-Type': 'application/json;charset=utf-8'
      },
    }).then(function successCallback(response) {
        var data = response.config.data
        console.log(data); //response received
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM