如何在php中打印或回显JSON.stringify数据

时间:2022-08-27 18:12:36

i am trying to fetch google contact list using contact api. i got the result and its showing in chrome and firefox console. i want to print the data in php. on the same page

我正在尝试使用联系人api获取谷歌联系人列表。我得到了结果和它在chrome和firefox控制台中的显示。我想在php中打印数据。在同一页上

<script type="text/javascript">
       function auth() {
         var config = {
           'client_id': 'xxxxxxxxxxxxxxxxxxxxx',
           'scope': 'https://www.google.com/m8/feeds'
         };
         gapi.auth.authorize(config, function() {
           fetch(gapi.auth.getToken());  

         });
       }

       function fetch(token) {
         $.ajax({
         url: "https://www.google.com/m8/feeds/contacts/default/full?access_token=" + token.access_token + "&alt=json",
         dataType: "jsonp",
         success:function(data) {

             //alert(JSON.stringify(data));
                                  // display all your data in console
                    console.log(JSON.stringify(data));

         }
         });
     } 
    </script>

i tried ajax but not worked. is there any best way to do it. JSON.stringify(data) is a array

我试过ajax但没有工作。有没有最好的方法来做到这一点。 JSON.stringify(data)是一个数组

1 个解决方案

#1


0  

You have nothing to do with PHP here. You are receiving a callback from $.ajax and the only way to show that data on ur page is to use JavaScript/jQuery.

你在这里与PHP无关。您正在接收来自$ .ajax的回调,并且显示您页面上的数据的唯一方法是使用JavaScript / jQuery。

See example below on how to parse $.ajax callback and .append() the data to some element on ur page:

请参阅下面的示例,了解如何将$ .ajax回调和.append()数据解析到ur页面上的某个元素:

<div id="contacts"></div>


function fetch(token) {
   $.ajax({
      url: "https://www.google.com/m8/feeds/contacts/default/full?access_token=" + token.access_token + "&alt=json",
      dataType: "jsonp",
      success:function(data) {
         $.each(data.feed.entry,function(){                    
            $('#contacts').append('<div>Name: ' + this.title.$t + ' Phone: ' + this.gd$phoneNumber[0].$t + '</div>');
            console.log('Name: ' + this.title.$t + ' Phone: ' + this.gd$phoneNumber[0].$t);
         });

       }
   });
}

Note: if You need to parse ur data with PHP then You have to use curl.

注意:如果您需要使用PHP解析您的数据,那么您必须使用curl。

#1


0  

You have nothing to do with PHP here. You are receiving a callback from $.ajax and the only way to show that data on ur page is to use JavaScript/jQuery.

你在这里与PHP无关。您正在接收来自$ .ajax的回调,并且显示您页面上的数据的唯一方法是使用JavaScript / jQuery。

See example below on how to parse $.ajax callback and .append() the data to some element on ur page:

请参阅下面的示例,了解如何将$ .ajax回调和.append()数据解析到ur页面上的某个元素:

<div id="contacts"></div>


function fetch(token) {
   $.ajax({
      url: "https://www.google.com/m8/feeds/contacts/default/full?access_token=" + token.access_token + "&alt=json",
      dataType: "jsonp",
      success:function(data) {
         $.each(data.feed.entry,function(){                    
            $('#contacts').append('<div>Name: ' + this.title.$t + ' Phone: ' + this.gd$phoneNumber[0].$t + '</div>');
            console.log('Name: ' + this.title.$t + ' Phone: ' + this.gd$phoneNumber[0].$t);
         });

       }
   });
}

Note: if You need to parse ur data with PHP then You have to use curl.

注意:如果您需要使用PHP解析您的数据,那么您必须使用curl。