【问题标题】:$.ajax call for Kohana 3.2 controller returns 404Kohana 3.2 控制器的 $.ajax 调用返回 404
【发布时间】: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


【解决方案1】:
<?php URL::base()?>reports/xml  

这很可能返回 http://www.yoursite.comreports/xml aka,404。

改成:

<?php URL::base()?>/reports/xml

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-10-19
  • 2019-10-06
  • 2018-07-05
  • 2020-08-13
  • 2023-04-01
  • 2012-01-21
  • 1970-01-01
  • 2018-11-07
相关资源
最近更新 更多