javascript - AngularJS "TypeError: Cannot read property 'protocol' of undefined" When get post data from web service -
i'm trying data web service. here code.
$scope.savepricing = function(){ var pricing = { "pricingschemeid": 0, "name": $scope.name, "lastusername": "tan", "lastmodifieddate": "", "isactive": true, "currencyid": $scope.selectedcurrency.currencyid, } $http({ url: config.addpricing, data: pricing, method: "post" }).success(function(data){ alert("success"); }).error(function(data){ alert("failed"); }); })
but when run function, error shown:
what can now?
config.addpricing
undefined. can reproduce error follows:
index.html
:
<!doctype html> <html ng-app="foo"> <head> <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script> <script src="my-angular.js"></script> </head> <body ng-controller="somectrl"> <button ng-click="go()">go</button> </body> </html>
my-angular.js
:
var app = angular.module("foo", []); app.controller("somectrl", function($scope, $http) { var config = {}; // note lack of "url" field. $scope.go = function() { $http({ url: config.url, // undefined data: {}, method: "post" }).success(function(data) { console.log("success: data", data); }).error(function(data) { console.log("error: data", data); }); }; });
Comments
Post a Comment