1

I am trying to pass data to node js http request (firebase cloud functions) via POST method.

angular.module('app', ['ionic'])
.controller("HttpGetController", function ($scope, $http) {
  var ph_array = [];
  ph_array.push('a');
  ph_array.push('b');
  ph_array.push('c');
  var data = {
    ph_id : ph_array
  };
  $scope.GetAllData = function(){
      $http.post('http://localhost:5002/xxxxx-f4286/us-central1/xxxxxxxxxxxxxxxxxxx', data).then(function successCallback(response) {
        alert('success');
        alert('response '+JSON.stringify(response));
        alert('status '+response.status);
        console.log('response '+JSON.stringify(response))
      }, function errorCallback(response) {
        alert('failure '+response.status+' msg '+response.data);
      });
  }
  });

Node js in firebase cloud functions

exports.xxxxxxxxxxxxxxxxxxx = functions.https.onRequest((request, response) => {
    console.log('request.method '+request.method);
    const ph_ids = request.body.ph_id;
    console.log('ph_ids '+ph_ids);
    response.send('I am done');
});

Log are coming as

info: User function triggered, starting execution
info: request.method OPTIONS
ph_ids undefined
info: Execution took 0 ms, user function completed successfully

Could someone help me what I am doing wrong here.

KENdi
  • 7,576
  • 2
  • 16
  • 31
kpvsrkp
  • 335
  • 2
  • 12

0 Answers0