【发布时间】:2012-03-22 23:11:34
【问题描述】:
使用 Kohana 3.2、JQuery 1.4.4、Firefox 浏览器, 试图让 $.ajax 调用正常工作,但它总是返回 404 错误
这是我的配置 我使用的网址是 127.0.0.1/xyz/kdi
我的 URL::base() 是 xyz/kdi -> 执行 Reports/welcome.php 索引操作
我的引导路线:
Route::set('default', '(<directory>(/<controller>(/<action>(/<id>))))')
->defaults(array(
'directory' => 'reports',
'controller' => 'welcome',
'action' => 'index',
));
控制器:
1. 控制器/报告/welcome.php
2.控制器/报告/xml.php
观看次数:
1.views/reports/mainReport.php(由welcome.php调用)
2.views/reports/xml.php
将以下请求放入 mainReport.php 中的控制器 xml 效果很好。
<?php echo Request::factory('reports/xml/index/77')->execute(); ?>
这是我在视图中使用的 $.ajax 调用:
$.ajax({
type:'POST',
url: '<?php URL::base()?>reports/xml', // <--- this is the problematic line
cache: false,
dataType:'json',
data:{params:param},
success: function(resultArray, textStatus, XMLHttpRequest){
alert('success');
}
});
我的 XML 控制器看起来像这样
class Controller_Reports_Xml extends Controller_BlankLayout {
public function __construct(Request $request, Response $response){
parent::__construct($request, $response);
}
public function action_index(){
if ($this->request->is_ajax()) {
$params = json_decode($_POST['params']);
echo Debug::vars($params);
//echo 1/0;
$this->auto_render = FALSE;
}else{
$id = $this->request->param('id');
$this->template->content = 'success to receive the param '.$id;
}
}
}
为什么我得到404,在网上到处搜索显示ajax调用是正确的,这让我认为它与Kohana配置有关。
提前致谢
【问题讨论】:
-
echo 1/0;你想做什么?引发致命错误? -
它是用于调试的,并不是代码的一部分。我只是评论了它。谢谢
标签: jquery ajax json kohana-3 php