javascript - $http GET URL changes and looks for wrong resource -


i'm developing single page application. making use of angularjs.v1.2.28. i'm making http request backend using code.

return {         getcategories : function(sessionid,terminalid,tableno,section){              var req = {                      method: 'get',                      url: config.url+ "/menucategories",                      params : {                          'sessionid' : sessionid,                          'terminalid' : terminalid,                           'tableno' : tableno,                          'section' : section                      }             };              return $http.get(req);         }, 

i make use of promise object returned service in controller.

var categorypromise = categoryservice.getcategories(sessionid,terminalid,tableno,section);     categorypromise.then(function(payload){         var categories =  payload.data;          if(categories.status.code == "1"){             if(object.prototype.tostring.call(categories) === '[object array]') {                 $scope.categories = categories;                 categoryservice.setcategories(categories);                 $scope.pax = tableservice.getpax();                 $scope.tablechair = tableservice.getchosetablechair();             }         }         else{             $location.url("/login");             $scope.errormsg = categories.status.desc;         }     },function(errorpayload){         $location.url("/login");         $scope.errormsg = "server error while processing request.please contact system administrator";     }); 

it's errorcallback getting called due url getting changed browser application url appended malformed characters. url give

http://localhost:8080/cafexrestful/menucategories 

but, gets changed browser application url below

http://localhost:8080/cafexmobile/[object%20object] 

i have been debugging in chrome , firebug. couldn't resolve it. may happening under hood. same code working controller , service, fetch different data. please let me know if need anymore information. thanks.

$http.get in angularjs needs url string. should use url string instead of object

using $http.get function:

  return {             getcategories : function(){                  return $http.get("/menucategories"); // using $http.get function.             }, 

using $http function.

return {         getcategories : function(sessionid,terminalid,tableno,section){              var req = {                      method: 'get',                      url: config.url+ "/menucategories",                      params : {                          'sessionid' : sessionid,                          'terminalid' : terminalid,                           'tableno' : tableno,                          'section' : section                      }             };              return $http(req); //using $http function only.         }, 

please see document: https://docs.angularjs.org/api/ng/service/$http


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -