0

I'm trying to return a value from a JSON Object in a JS function, this is my code:

function verifyActive(numEmpleado){
    var id_codigo = 0;
    try{
        var dataString="oper=11&hidNumEmpleadoN="+numEmpleado;
            $.ajax({
                type: "GET",
                url:"./negReporteStatusHH.jsp",
                cache: false,
                data: dataString,
                datatype:"json",
                success: function(data){
                    console.log(data);
                    var jsonObj = data;
                    var jsonResult = JSON.parse(jsonObj);
                    var arr = [];
                    for(var x in jsonResult){
                        arr.push(jsonResult[x]);
                    }
                    console.log(arr[0]);
                    console.log(jsonResult);
                    id_codigo = arr[0];
                }
            });
            return id_codigo;
        }catch(e){
            return id_codigo;
        }
 }

The JSON Object obtained is the following:

{RIDCODIGO: 1, RDESCIDCODIGO: "WE HAVE DATA        ", RIDSTATUS: 1, RDESCIDSTATUS: "ACTIVE     "}

I want to return the RIDCODIGO value. Any question post on comments.

TimeToCode
  • 901
  • 2
  • 16
  • 34

0 Answers0