jeudi 22 février 2018

JSON Response TypeError - Nested Data

I have a JSON response, one that is throwing me for a rather annoying loop. Here is my current response that I receive.

enter image description here

This is my ajax script:

<script>
 $(document).on('click', '#pullDetails', function() {
         $.ajax({
            type:'POST',
            url: '/carrier/claims/pullDetails',
            data: {
                num: $('input[name=proNumber]').val(),
                _token: $('input[name=_token]').val()},
            dataType: 'json',
            success: function(data) {
                if(data.details != undefined) {
                        console.log('success');
                        console.log(data.details.SearchResults[0].Shipment.Origin.Name); //result: ATLAS INTL
                        $('#carrierReturnData').html(data.details.SearchResults[0].Shipment.Origin.Name);
                    }else{
                        console.log('failed');
                        console.log(data);
                        console.log(data.details.SearchResults.SearchItem); 
                    }
            },
            error: function(data) {
                console.log('error');
                console.log(data);
            }
        });
    });
</script>

Now my question is how would I get the specific data from the line "SearchItem" (on the first line of the response json)?

At the moment I get the following: TypeError: data.details.SearchResults is undefined, but data.details is recognized as my console logs "success."

Thanks - Matt



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire