我正试图从这个ajax函数中获取正确的信息(缩略图,图像的所有者)。 我不认为它知道data.images [i] .imgurl和data.images [i] .username是什么。

ajax.php

  require_once 'instagram.class.php';

  // Initialize class for public requests
  $instagram = new Instagram('123456');

  // Receive AJAX request and create call object
  $tag = $_GET['tag'];
  $maxID = $_GET['max_id'];
  $clientID = $instagram->getApiKey();

  $call = new stdClass;
  $call->pagination->next_max_id = $maxID;
  $call->pagination->next_url = "https://api.instagram.com/v1/tags/{$tag}/media/recent?client_id={$clientID}&max_tag_id={$maxID}";

  // Receive new data
  $media = $instagram->getTagMedia($tag,$auth=false,array('max_tag_id'=>$maxID));

  // Collect everything for json output
  $images = array();

  foreach ($media->data as $data) {
 $images[] = array(
           "imgurl"=>$data->images->thumbnail->url,
        "username"=>$data->user->username;
        );
    }

  echo json_encode(array(
    'next_id' => $media->pagination->next_max_id,
    'images'  => $images,

  ));

search.php中

<script>
   $(document).ready(function() {
    $('#more').click(function() {
    var tag   = $(this).data('tag'),
        maxid = $(this).data('maxid'),


    $.ajax({
      type: 'GET',
      url: 'ajax.php',
      data: {
        tag: tag,
        max_id: maxid

      },
      dataType: 'json',
      cache: false,
      success: function(data) {
        // Output data
        $.each(data.images, function(i, src) {

          $('#photos').append('<div id=box><div class=mainimg><img src="'+  data.images[i].imgurl +'"></div><div class=\"pfooter\">'+ data.images[i].username +'</div></div>');
        });

        // Store new maxid
        $('#more').data('maxid', data.next_id);
      }
    });
  });
});

..

===============>>#1 票数:2

search.php文件中,您必须用分号关闭变量语句。

改变这一行:

var tag   = $(this).data('tag'),
    maxid = $(this).data('maxid'),

对此:

var tag   = $(this).data('tag'),
    maxid = $(this).data('maxid'); // <-- added semicolon

  ask by BrandN00b translate from so

未解决问题?本站智能推荐: