[英]jQuery Post Returning Nothing
I created a simple jQuery post that returns data every time an user types in a character in an input field. 我创建了一个简单的jQuery帖子,每当用户在输入字段中输入字符时,该帖子都会返回数据。 The problem is that it is not working.
问题是它不起作用。 Firebug returns no errors.
Firebug不返回任何错误。 When I type in a keyword FireBug Net shows no requests made.
当我输入关键字时,FireBug Net不会显示任何请求。 My code is almost a cut and paste from another piece of code that does work.
我的代码几乎是另一段有效的代码的剪切和粘贴。 I have no idea what to do and this is not the first time something like this has happened.
我不知道该怎么办,这不是第一次发生这样的事情。
Here is the original file. 这是原始文件。
<input type="text" id="search_tags" />
<div id="tag_results"></div>
<script type="text/javascript" >
$(document).ready(function() {
$('#search_tags').keyup(function() {
var search_term = $(this).val();
$.post('ajax_file.php', {search_term: search_term}, function (data) {
$('#tag_results').html(data);
});
});
$('#search_tags').bind('keydown', function(e) {
if(e.keyCode==13){
e.preventDefault();
};});
});
</script>
Here is the ajax file. 这是ajax文件。
$search_term = sanitize($_POST['search_term']);
if (!empty($search_term)) {
$search = mysql_query("SELECT DISTINCT `tag_name` FROM `tags` WHERE `tag_name` LIKE
'%$search_term%' LIMIT 0, 15");
$y = 1;
while ($results_row = mysql_fetch_assoc($search))
{
echo '<br><br>' . $results_row['tag_name'] . '<br><br><hr>';
$y++;
}}
Well: 好:
$('#search_tags_').keyup(...
should be: 应该:
$('#search_tags').keyup(...
because I can't see an element with id="search_tags_"
in your example which has: 因为在您的示例中我看不到
id="search_tags_"
的元素,该元素具有:
<input type="text" id="search_tags" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.