2017-08-11 3 views
0

ためAPIKEYを隠して、私はセキュリティ上の理由からAPIKEYを隠してt know how fetch that json配列and print it using $ .each`機能印刷JSONデータ、私はまた、AJAXコードを含むセキュリティ上の理由

を着用、私はそこにあることは明らかですJSONレスポンスを取得中にエラーが、私は応答 を取得していますconsole logにチェックして、私は、それを取得に問題を抱えているいくつかのいずれかが私を助けることができる

JSONデータ

なし
{"data":[{"title":"Zimbabwe A 162/4 * v South Africa Emerging Players 454/10 ","description":"Zimbabwe A 162/4 * v South Africa Emerging Players 454/10 ","unique_id":"1114833"},{"title":"Vanuatu Under-19s 105/10 * v Papua New Guinea Under-19s 136/10 ","description":"Vanuatu Under-19s 105/10 * v Papua New Guinea Under-19s 136/10 ","unique_id":"1110907"},{"title":"Fiji Under-19s 80/10 * v Samoa Under-19s 110/10 ","description":"Fiji Under-19s 80/10 * v Samoa Under-19s 110/10 ","unique_id":"1110908"},{"title":"St Lucia Stars 129/6 * v Barbados Tridents 196/4 ","description":"St Lucia Stars 129/6 * v Barbados Tridents 196/4 ","unique_id":"1094679"},{"title":"Boost Region v Speen Ghar Region 92/3 *","description":"Boost Region v Speen Ghar Region 92/3 *","unique_id":"1115761"},{"title":"Band-e-Amir Region v Mis Ainak Region 156/3 *","description":"Band-e-Amir Region v Mis Ainak Region 156/3 *","unique_id":"1115762"},{"title":"Derbyshire v West Indies","description":"Derbyshire v West Indies","unique_id":"1059662"},{"title":"Yorkshire Diamonds v Lancashire Thunder","description":"Yorkshire Diamonds v Lancashire Thunder","unique_id":"1093477"},{"title":"Karaikudi Kaalai v Ruby Trichy Warriors","description":"Karaikudi Kaalai v Ruby Trichy Warriors","unique_id":"1107277"},{"title":"Munster Reds v Leinster Lightning","description":"Munster Reds v Leinster Lightning","unique_id":"1089622"},{"title":"Northern Knights v North-West Warriors","description":"Northern Knights v North-West Warriors","unique_id":"1089621"},{"title":"Durham v Worcestershire","description":"Durham v Worcestershire","unique_id":"1068397"},{"title":"Northamptonshire v Leicestershire","description":"Northamptonshire v Leicestershire","unique_id":"1068399"},{"title":"Nottinghamshire v Warwickshire","description":"Nottinghamshire v Warwickshire","unique_id":"1068396"},{"title":"Yorkshire v Lancashire","description":"Yorkshire v Lancashire","unique_id":"1068401"},{"title":"Essex v Middlesex","description":"Essex v Middlesex","unique_id":"1068398"},{"title":"Kent v Hampshire","description":"Kent v Hampshire","unique_id":"1068395"},{"title":"Sussex v Gloucestershire","description":"Sussex v Gloucestershire","unique_id":"1068400"},{"title":"Trinbago Knight Riders v Guyana Amazon Warriors","description":"Trinbago Knight Riders v Guyana Amazon Warriors","unique_id":"1094680"}],"cache":false,"v":"1","ttl":212,"provider":{"source":"Various","url":"https://cricapi.com/","pubDate":"2017-08-11T06:45:52.376Z"},"creditsLeft":238} 

AJAX CODE(私はセキュリティ上の理由からAPIキーを持っています)。

$.ajax({ 
     type: 'GET', 
     url: 'http://cricapi.com/api/cricket/?apikey=keyIsHiddenForSecurityReasons', 
     dataType: 'json', 
      success:function(data){ 
      console.log(data.data); 
      } 

     }); 

答えて

0

これを試してみてください:成功コールバックで

$.ajax({ 
      type: 'GET', 
      url: 'http://cricapi.com/api/cricket/?apikey=keyIsHiddenForSecurityReasons', 
      dataType: 'json', 
       success:function(data){ 
       console.log(data.data); 

        $.each(data.data, function(indx,obj) { 
        alert(obj.title) 
        }); 
       } 

}); 
1

$.eachを使用して、いくつかのマークアップに追加し、私はあなたの答えからソリューションを得た回答を

success:function(data){ 
    $.each(data.data, function(index, obj){ 
     console.log(obj.title ,obj.description, obj.unique_id); 

     //append to markup for example, like this 
     $('#foo').append('<span>'+obj.title+'</span><span>'+obj.description+'</span>') 
    }) 
} 
+1

おかげで、それは本当に私をたくさん助けました – anbu

関連する問題