ajax input value,jquery - Input value in ajax call does not work - Stack Overflow

I am working on a small trial and error project which allows you to simply search photos on Instagram. I found this example and it works flawlessly. Unfortunately, you can only use one static tag in that example. What I am trying to do is allow a user to search for a tag. That input value is then used as the tag that is used in the ajax call. Unfortunately this doesn't work. No errors in console or anything. Just no response.

jQuery

// Search new tag

$("form#s-form > button").click(function () {

if (!$("form#s-form > input").val()) {

// notice no value given

} else {

var tag = $("form#s-form > input").val(), // Here is the tag

maxid = $("#more").data("maxid");

// change the data-tag to the tag that is searched for

$("#more").data("tag", tag); // this does NOT work

$.ajax({

type: "GET",

url: "ajax.php",

data: {

tag: tag, // Here it is used in ajax

max_id: maxid

},

dataType: "json",

cache: false,

success: function (data) {

// Clear current data

$("div#photos").empty();

// Output data

$.each(data.images, function (i, src) {

$("div#photos").append('

');

});

// Store new maxid

$("#more").data("maxid", data.next_id);

// Some extra functions

}

});

}

});

HTML/PHP

/**

* Instagram PHP API

*/

require_once 'instagram.class.php';

// Initialize class with client_id

// Register at http://instagram.com/developer/ and replace client_id with your own

$instagram = new Instagram('MYCLIENT_ID');

// Show 'load more' button

echo 'Meer foto\'s?';

?>

Zoek!

Foto's toegevoegd
Scroll naar beneden

ajax.php

/**

* Instagram PHP API

*/

require_once 'instagram.class.php';

// Initialize class for public requests

$instagram = new Instagram('MYCLIENT_ID');

// 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[] = $data->images->standard_resolution->url;

}

echo json_encode(array(

'next_id' => $media->pagination->next_max_id,

'images' => $images

));

?>

Yes I filled in my client ID :)

And instagram.class.php but adjusted as the answer previously mentioned suggested.

Any help or direction with this?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值