0

I have a JSON response, one that I can't figure out. 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."

Image 1

Image 2

Image 3

1 Answer 1

1

Do a JSON.parse of details and then try to log SearchResults

var results = JSON.parse(data.details);
console.log(results.SearchResults.SearchItem);
Sign up to request clarification or add additional context in comments.

3 Comments

That specifically returns success (as part of the first portion) and then undefined. However (and I'll edit my question above to include the images), if I remove the .SearchItem and just keep it as results.SearchResults, I get an array returned. Give me a few moments...
I've added images to show what the console return looks like.
Using your suggestion above, I edited to work as such: results.SearchResults[0].SearchItem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.