How to send an arrangement to a web services in angularjs?

2

Hi I am consuming the data of a web services with JSON and the problem is that I am doing the same request twice because id_servicio contains two numbers in an array (38 and 39) and these return me different data. (they are different branches) for now I'm sending id_servicio in the following way:

petition 1:

      $scope.DateNormal = Ticket.getAll({

    id_usuario: LoginData.getData().id_usuario,
    token: LoginData.getData().token,
    id_sucursal: LoginData.getData().id_sucursal,
    id_servicio: LoginData.getData().id_servicio.split(",")[0],

petition 2:

      $scope.DatePriority = Ticket.getAll({

    id_usuario: LoginData.getData().id_usuario,
    token: LoginData.getData().token,
    id_sucursal: LoginData.getData().id_sucursal,
    id_servicio: LoginData.getData().id_servicio.split(",")[1],

My question is: can I send both of one? How?.

Data:

  • Respond with data in JSON
  • LoginData.getdata () corresponds to other data received in JSON from a web services and saved in this variable.

Greetings.

    
asked by Hernan Humaña 26.09.2016 в 19:15
source

3 answers

1

If the Ticket.getAll service receives an array of service_id, yes. You could do it in the following way:

$scope.DateNormal = Ticket.getAll({
    id_usuario: LoginData.getData().id_usuario,
    token: LoginData.getData().token,
    id_sucursal: LoginData.getData().id_sucursal,
    id_servicio: LoginData.getData().id_servicio
});
    
answered by 14.03.2017 в 06:43
0

Your question is not well understood but I hope this is the answer. It is not necessary to make 2 requests, you can send the 2 numbers as an array or as a string. but for that you would have to modify your service and allow to accept n ids either in array or in chain.

var Dates = Ticket.getAll({
    id_usuario: LoginData.getData().id_usuario,
    token: LoginData.getData().token,
    id_sucursal: LoginData.getData().id_sucursal,
    //opciones dependiendo de que te devuelva LoginData.getData().id_servicio
    id_servicio: LoginData.getData().id_servicio  // <-- [38,39] 
    id_servicio: LoginData.getData().id_servicio.join(",") // [38,39] --> "38,39"
    id_servicio: LoginData.getData().id_servicio.split(",") // "38,39" --> [38,39]
});
$scope.DateNormal = Dates[0];  
$scope.DatePriority = Dates[1]; 

If you do not want to modify your service in any case, gentleman, you should make 2 requests

    
answered by 20.10.2016 в 19:18
0
  

My question is: can I send both of one? How?.

Your question does not have to do with how to treat the JSON from AngularJS, if not, your function in the WS that can receive 1 or more parameters, in this case service_id and return the expected data for each one.

And the answer is: YES, configure your WS so that it is able to receive an ID or service-type Objective array to be able to 1 by 1 iterate and do what you need. In these moments the function of your WS must be waiting:

Ticket.getAll({
    id_usuario: LoginData.getData().id_usuario,
    token: LoginData.getData().token,
    id_sucursal: LoginData.getData().id_sucursal,
    id_servicio: LoginData.getData().id_servicio.split(",")[0]
})

If you want to send 2 or more you must prepare it so that it can receive different objects with this same structure.

Greetings!

    
answered by 20.10.2016 в 20:54