我正在尝试为即时输入更改上的关键字执行数据库查询。现在,我得到一个成功的查询,并存储了所有结果,但在GET
上显示它们,我的ajax
函数返回false。它为什么这样做?AJAX返回false但我不明白为什么?
控制台输出:
POST http://example.com/functions/ajax.php
response: the data i need to display
接着是
GET http://example.com/functions/ajax.php
response: false
这里是我的JS:
<script id="source" language="javascript" type="text/javascript">
$(function() {
$('#url').bind('input', function() {
$(this).val() // get value
$.ajax({
type: 'POST',
url: 'functions/ajax.php',
data: {
url: $('#url').val()
},
success: function (data) //on receive of reply
{
$(function() {
$.ajax({
url: 'functions/ajax.php', //the script to call to get data
data: "", //you can insert url arguments here to pass to api.php
//for example "id=5&parent=6"
dataType: 'json', //data format
success: function (data) //on receive of reply
{
var namePHP = data[1];
var categoryPHP = data[2];
//--------------------------------------------------------------------
// 3) Update html content
//--------------------------------------------------------------------
$('#name').html(namePHP); // # name and #category are input fields I want autofilled
$('#category').html(categoryPHP);
}
});
});
}
});
});
});
</script>
ajax.php
<?php
require_once ('DBconnect.php');
$url = $_POST['url'];
$url = mysqli_real_escape_string($con, $url);
$query = "SELECT * FROM `inserted_posts` WHERE `search_name` = '$url'";
$result = mysql_query($query);
$array = mysql_fetch_array($result);
echo json_encode($array);
?>
为什么你的回调做一个AJAX调用同一个页面拉AJAX呼叫? – 2013-04-24 18:19:20
@RocketHazmat:为什么不呢?不同的方法,参数和数据类型:-) – Bergi 2013-04-24 18:29:48
[希望自动填充输入栏与AJAX](http://stackoverflow.com/questions/16199886/want-to-auto-fill-input-bars-with- ajax) – Musa 2013-04-24 23:40:47