0

I'm trying to get the return value "dataJson", but I got undefined exactly.

Would anyone tell my how can I do to get it??

thank you very much!

    $scope.sendRequest = function (port) {
        var dataJson;
        $http({
           method: "GET",
           url: CCHK3AnalysisWebserviceUrl + `/Get` + port + `ForPC?PageSize=10000&PageCount=1&ConditionJson=` + CondtJson,
          }).then(function (data) {
                dataJson = $scope.parseData(data.data);
          }, function (err) {
                console.log(err)
          })
            return dataJson
         }
Sylvia
  • 257
  • 2
  • 6
  • 16
  • 1
    This is enough: `$scope.sendRequest = function(port){ return $http.get(url).then(function(data){return data.data;})`. But this will return a Promise with your data, you need to resolve it elsewhere as: `$scope.sendRequest(port).then(function(data){var dataJson = data; ...})` – Aleksey Solovey Sep 12 '18 at 13:12
  • It's undefined because you haven't initialised the variable and if it's not a success response it will never set any value as the `dataJson` is not assigned in error response it will return `undefined`. – Nikhil Zurunge Sep 12 '18 at 16:40

0 Answers0