在CakePHP 2.1上,我有一个获取空响应的ajax请求(使用firebug检查)并且还触发错误回调。
从我的.js开始,我在蛋糕 - 服务器之外调用一个php来提供我需要的一些数据库记录:
function updateDiv() {
$.ajax({
url: 'http://myserver/phpGenesi/api.php',
data: "",
dataType: 'json',
success: function(data)
{
alert(data);
},
error: function(data)
{
alert('error')
}
});
}
这是服务器上的PHP代码(它运行良好,不是CakePHP,只是PHP数据库):
$result = mysql_query("SELECT * FROM $tableName where project_id = 101");
$array = mysql_fetch_row($result);
if (mysql_num_rows($result) > 0)
{
$responses = array();
while($row = mysql_fetch_assoc($result)) {
$responses[] = array(
'id' => $row['id'],
'name' => $row['name'],
'dir_description' => $row['dir_description'],
'project_id' => $row['project_id'],
'dir_notes' => $row['dir_notes'],
'dir_dataname' => $row['dir_dataname']
);
}
echo '{"dirs": ' . json_encode($responses) . '}';
}
当我从外面的蛋糕访问相同的php时,我得到的结果很好,例如:
http://myserver/phpGenesi/api.php
返回我需要的内容:
{"dirs": [{"id":"240","name":"c","dir_description":"Carlos Test c","project_id":"101","dir_notes":"c","dir_dataname":"c"},{"id":"241","name":"d","dir_description":"Carlos Test d","project_id":"101","dir_notes":"d","dir_dataname":"d"}]}
从任何客户文档调用时也可以。
问题是当我从蛋糕文件中调用它时。 Firebug显示空响应,触发了我的ajax错误功能。
知道它缺少什么?我怎么知道触发我的错误功能的错误是什么?