使用ajax打印json数据,出于安全原因我隐藏了APIKEY

时间:2017-08-11 07:10:10

标签: php json ajax

我还包含了ajax代码,我没有t know how fetch that json数组and print it using $。每个功能

我出于安全原因隐藏了APIKEY,我很清楚获取json响应没有错误,我已经检入了console log我收到了回复 ,我在获取它时遇到问题,可以帮助我一些人

JSON DATA

{"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代码(我有安全原因的API密钥)。

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

        });

2 个答案:

答案 0 :(得分:1)

成功回调时使用server.cors: true server.cors.origin: "*" server.cors.credentials: true server.cors.methods: "GET, POST, PUT, DELETE, OPTIONS, HEAD" server.cors.headers: "Origin, X-Requested-With, Content-Type, Accept, Engaged-Auth-Token" 并将其附加到某个标记,

$.each

答案 1 :(得分: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)
                    });
                }

});