search

Home  >  Q&A  >  body text

angular.js - Problems with $http.post request data when using angular

When using $http.post in angular to request data, I found that the data after each request is the updated data when viewed in the console Network, but in $http.post (data address, parameters). success(function(response){$scope.datas=response.data;
console.log(response.data.vote_options) //This is the printed data but it is different from the data viewed in the console (a certain parameter value) Inconsistent, why??}), please see the specific code below:

            var voteposturl="/Api/Share/GetVoteInfo";
            var votepostparameter="&nid="+nid+"&vote_id="+$scope.voteid;
            $http.post(voteposturl,votepostparameter).success(function(response){
                $scope.datas=response.data; //总体数据
                console.log(response.data.vote_options) //现打印其数据结构中具体的一个数组数据
                console.log(response.data.vote_options[0].is_voted) //现打印其数据结构中具体的一个数组数据里面具体一条数据中的参数值,该参数值与在控制台查看的接口那里的数据又是保持一致,不知道为什么会这样
            }) 

Please see the data comparison after the request:

  1. This is the printed data //console.log(response.data.vote_options)

  2. ##This is the real data of the network when viewing the requested interface on the console

Does anyone know what causes this? Is it because $http is cached? Or is it because of other reasons?

为情所困为情所困2856 days ago966

reply all(3)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-27 17:46:38

    Change your browser and see if the problem is the same. Chrome has some bugs

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-27 17:46:38

    It is likely that its value has been modified in some places in your code.
    Print response.data above $scope.datas = response.data;. Check if it is consistent with the console

    reply
    0
  • 某草草

    某草草2017-05-27 17:46:38

    Maybe you performed data operations in some places you didn’t pay attention to. Angular is not good at this. If you move it slightly, everything will change.

    reply
    0
  • Cancelreply