javascript - consuming a web api and getting a referenceerror -


when trying post , data web api, getting exception in browser:

angular.js:13708 referenceerror: $ not defined @ new (gbyg.js:23) @ object.invoke (angular.js:4709) @ $controllerinit (angular.js:10234) @ nodelinkfn (angular.js:9147) @ compositelinkfn (angular.js:8510) @ nodelinkfn (angular.js:9210) @ compositelinkfn (angular.js:8510) @ compositelinkfn (angular.js:8513) @ compositelinkfn (angular.js:8513) @ publiclinkfn (angular.js:8390)

here client (written in angular):

app.controller('getsamplesbystatus', function($scope, $http) {     var serializeddata = $.param({statustype:"received"});      $http({         method: 'post',         url: ("http://localhost:36059/api/samples/getsamplesbystatus"),     data: serializeddata,     headers: {         'content-type': 'application/json'     }}).then(function(response) {         //$scope.dataset = response;         console.log(error);     }, function(error) {         console.log(error);     }); }); 

what doing wrong?

see angular docs $httpparamserializerjqlike same serialisation work jquery.param() link

.controller(function($http, $httpparamserializerjqlike) {   //...    $http({     url: myurl,     method: 'post',     data: $httpparamserializerjqlike(mydata),     headers: {       'content-type': 'application/x-www-form-urlencoded'     }   });  }); 

so in case this:

app.controller('getsamplesbystatus',     function($scope, $http, $httpparamserializerjqlike) {         var myparams = {statustype:"received"};         $http({           url: "http://localhost:36059/api/samples/getsamplesbystatus%0a",           method: 'get',           params: myparams,           paramserializer: '$httpparamserializerjqlike'         }).then(function(response) {             //$scope.dataset = response;             console.log(response.data);         }, function(error) {             console.log(error);         });     }); 

see working example here: http://jsbin.com/madetefeya/edit?js,console


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -