Get specific JSON value

Asked

Viewed 74 times

0

I have an API that returns the corresponding image of a status, however I’m having trouble getting only the field 'camiofoto' in my API answer.

Response from the API:

({"code":1,"msg":"OK","details":[{"caminhofoto":"https:\/\/localhost\/sistema\/assets\/images\/status\/pendente.gif"}],"request":"{\"status\":\"pending\"}"})

Code I’m using to take the field truck:

$.ajax({
    type:"GET",
    url:"https://localhost/sistema/mobileapp/api/getImagemStatus?status=pending",
    data: { get_param: 'caminhofoto' }, 
    dataType: 'jsonp',
    success: function(data) {
        //Aqui tento pegar apenas o campo caminhofoto
        var foto = data['caminhofoto'];

        console.log("ENTROU AQUI "+foto)


    },

  });

In the console I get the log: Came in here Undefined

1 answer

1


The photo path is inside Details, at position 0 of the array.

console.log(data.details[0].caminhofoto);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.