2

I have a nodejs web service url. Through that I am able to perform authentication. I am using AJAX for that. I want to do the same operation with simple javascript.

This is my service.js code

var LOGIN_AUTHENTICATION = "http://192.168.84.88:8888/AD-Service/rest/getEmpDetails/authenticateUser";

this.getLoginAuthentication = function(taskObject) {
           var promise = null;
           if (!promise) {
               promise = $http({
               method: 'POST',
                url: LOGIN_AUTHENTICATION,
                data: taskObject,
                headers: {'Content-Type': 'application/json'}
                }).then(function(response) {
                   return response.data;
               });
           }
           return promise;
       }

This is my controller code..

ProjectServices.getLoginAuthentication($scope.loginData).then(function(data) {
    if(data=="true"){

     $state.go('app.calendar',{username:$scope.loginData.userName}); 

 }
else{
      $scope.myvalue = true;
      $scope.loginData.password=''; 
        }
    });

can anybody please help me how to do this in simple javascript..?

1 Answer 1

1

$http is just a wrapper for the XMLHttpRequest object that returns HTTP responses wrapped in $q promises. If you want to simulate that mechanism with plain JS, use the XMLHttpRequest object to send GET (or any other) requests and wrap the results with a Promise

http://mdn.beonex.com/en/DOM/XMLHttpRequest/Using_XMLHttpRequest.html

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.