Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello From 2-3 days,iam stucked in a new problem,actually i have to retrieve information using 'api url' that retrieves complex json array which is just like this-

{"response":{"success":true,"result":{"id":"45203511","device_id":"62970","message":"Rs. 20.00 refunded in your Paytm wallet for your order on Paytm. Updated balance:Rs. 20.0. Queries? Visit Paytm.com\/care.","status":"received","send_at":0,"queued_at":0,"sent_at":0,"delivered_at":0,"expires_at":0,"canceled_at":0,"failed_at":0,"received_at":1507375388,"error":"N\/A","created_at":1507375388,"contact":{"id":"9209301","name":"VK-IPAYTM","number":"VK-IPAYTM"}}},"status":200} 


I want to print an element from this json to console -

What I have tried:

My whole script part is:-
HTML
<script type="text/javascript"> var position ={}; $.ajax({ url:"my_api_url", type:"GET", success:function (data){ console.log(data.response.result.id); } }); </script>

It shows error :-
train2.php:23 Uncaught TypeError: Cannot read property 'result' of undefined at Object.success (train2.php:23) at i (jquery.min.js:2) at Object.fireWith [as resolveWith] (jquery.min.js:2) at A (jquery.min.js:4) at XMLHttpRequest.<anonymous> (jquery.min.js:4)
Posted
Updated 8-Oct-17 1:53am
v2
Comments
F-ES Sitecore 8-Oct-17 8:26am    
Double-check that's the actual JSON your method returns. Also use the script debugger tools of your browser to inspect the "data" variable to see what is in there.
Karthik_Mahalingam 12-Oct-17 0:55am    
it works as expected
var a = {"response":{"success":true,"result":{"id":"45203511","device_id":"62970","message":"Rs. 20.00 refunded in your Paytm wallet for your order on Paytm. Updated balance:Rs. 20.0. Queries? Visit Paytm.com\/care.","status":"received","send_at":0,"queued_at":0,"sent_at":0,"delivered_at":0,"expires_at":0,"canceled_at":0,"failed_at":0,"received_at":1507375388,"error":"N\/A","created_at":1507375388,"contact":{"id":"9209301","name":"VK-IPAYTM","number":"VK-IPAYTM"}}},"status":200} 
alert(a.response.result.id);


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900