javascript - Undefined variable $http request -
i'm performing - request on end retrieve json - data. want store part of data in variable because want use after request. everytime, variable undefined while did same thing in controller. can tell me i'm doing wrong?
this code:
var itemnumber; $http.get(urltoserver + 'serialnumber/' + $stateparams.serialnumber + '/?format=json').success(function(dataserialnumber){ itemnumber = dataserialnumber.id; }).error(function(){ //code }); console.log(itemnumber); item.number = itemnumber;
edit post call:
var postpromise = $http.post(urltoserver + 'problem/', item); postpromise.success(function (response) { angular.extend(item, response); showissuereportedalert($mddialog); $http.get('assets/settings/general.json').success(function(data){ companyurl = data[0].url; $timeout(function(){ //$window.location.href = companyurl; }, 3000); }); }); postpromise.error(function(){ showerroralert($mddialog); $scope.rendersendbutton = true; $scope.showprogresscircular = false; });
you can put post $http
call inside function
, call in .success
of get.
var itemnumber; $http.get(urltoserver + 'serialnumber/' + $stateparams.serialnumber + '/?format=json').success(function(dataserialnumber){ itemnumber = dataserialnumber.id; console.log(itemnumber); item.number = itemnumber; dopostcallnow(); //calling post }).error(function(){ //code }); function dopostcallnow(){ var postpromise = $http.post(urltoserver + 'problem/', item); //and rest of code... }
Comments
Post a Comment