<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({
type: "POST",
url: "http://localhost:8888/index.php/welcome/get_client/",
dataType: "json",
data: "{}",
success: function(data) {
var datafromServer = data.split(",");
("#search_client").autocomplete({
source: datafromServer
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
});
</script>
以上是我的jQuery代码。我真的从教程中得到它,但对于我的生活,我似乎无法得到它的工作,现在我想知道如果这是我的PHP PHP结果。jQuery自动完成:没有得到任何结果。有任何想法吗?
我的PHP是这样的:
function get_client()
{
$this->db->select('name')->from('clients');
$query = $this->db->get();
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($query->result());
}
当我赞同它,它看起来像这样:
[{"name":"Testing"},{"name":"Testing1"},{"name":"test11"},{"name":"test4"},{"name":"Testing21"},{"name":"Just Testing"},{"name":"testy"}]
我得到了以下JavaScript错误:
TypeError: Result of expression 'data.split' [undefined] is not a function.
不确定要做什么。
你设置的内容类型应用程序/ json在您的PHP HTTP响应头中? – padis 2011-02-01 22:20:14
你尝试过直接点击网址吗? – Victor 2011-02-01 22:20:42