Deepali Patil

Deepali Patil

  • NA
  • 4
  • 2.8k

using ajax along with angularjs

Feb 14 2014 12:16 AM
Hi,
 
   I want to hit the web service which is created by server side and url I know for it  and retrieve the json data if it is successful otherwise message should be failure. so how I should hit service using Ajax in AngularJs.The foll code I wrote Pls tell me any changes to be made OR any other way I should write the code
 
THIS CODE IS OF JAVASCRIPT
   angular.module('myModule', [])
  .service('ajaxRequest', function (url,data,successFn,errorFn,$http) {  })
  .controller('myController', ['ajaxRequest', function (url,data,successFn,errorFn,$http)

 

 {$http({  url: http://url of server side,
                  method: "POST",
             dataType:'json',
             data:{ empID:"1254556",
    password:"Pass",
    deviceId:"abc",
                }
 }).success(successFn).error(errorFn);
               
                successFn(data)
                {
                    alert(data);
                }
               
                errorFn(error)
                {
                    alert(error);
                }
               
                }]);
                              AND HTML PAGE IS
<!doctype html>
        <html>
     <script src=serviceController.js></script> and included angular min js file
<body ng-app="myModule"  ng-controller="myController">
</body>
 
</html>
 
 

this error is cmg

Error: [$injector:unpr] http://errors.angularjs.org/1.2.11/$injector/unpr?p0=urlProvider%20%3C-%20url%20%3C-%20ajaxRequest
    at Error (<anonymous>)
    at http://code.angularjs.org/1.2.11/angular.min.js:6:450
    at http://code.angularjs.org/1.2.11/angular.min.js:32:125
    at Object.c [as get] (http://code.angularjs.org/1.2.11/angular.min.js:30:200)
    at http://code.angularjs.org/1.2.11/angular.min.js:32:193
    at c (http://code.angularjs.org/1.2.11/angular.min.js:30:200)
    at d (http://code.angularjs.org/1.2.11/angular.min.js:30:417)
    at Object.instantiate (http://code.angularjs.org/1.2.11/angular.min.js:31:80)
    at Object.<anonymous> (http://code.angularjs.org/1.2.11/angular.min.js:31:343)
    at Object.d [as invoke] (http://code.angularjs.org/1.2.11/angular.min.js:30:452)
 

 
 
  

Answers (2)