ajax调用中的输入值不起作用

我正在进行一个小型的试错项目,它允许您在Instagram上搜索照片。 我找到了这个例子 ,它完美无缺。 不幸的是,在该示例中只能使用一个静态标记。 我想要做的是允许用户搜索标签。 然后将该输入值用作ajax调用中使用的标记。 不幸的是,这不起作用。 控制台或任何东西都没有错误。 只是没有回应。

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

 
<?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 ''; ?>
Foto's toegevoegd
Scroll naar beneden

ajax.php

 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 )); ?> 

是的我填写了我的客户端ID 🙂

和instagram.class.php但调整为前面提到的答案建议。

对此有何帮助或指导?

submit按钮的类型更改为button或取消提交表单

 

要么

 $("form").on("submit", function(ev) { ev.preventDefault(); });