Reputation: 1655
I have a JSON response, one that I can't figure out. Here is my current response that I receive.
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."
Upvotes: 0
Views: 37
Reputation: 26
Do a JSON.parse of details and then try to log SearchResults
var results = JSON.parse(data.details);
console.log(results.SearchResults.SearchItem);
Upvotes: 1