我正在尝试立即对输入更改的关键字进行数据库查询。现在,我得到了一个成功的查询,所有结果都存储了,但是在GET
显示它们时,我的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);
?>