javascript - 无法获取url参数

标签 javascript php jquery ajax phalcon

我使用了 ajax url 和我从选项框中选择的一个参数月份

  $.ajax({
    url: baseUri + 'attendancelist/search/attsearch/month/' + month ,
    type: 'GET'
    ...
        });

所以我想在我的 attsearchAction() 中调用该参数 所以我这样编码

public function attsearchAction() {        
    $month = $this->request->get('month');  //current testing framework is phalcon
    //$month = $this->_request->getParam('month'); //zend framework is ok by getParam
    var_dump($month);exit;     //null
   }

但它只显示null?如何解决这个问题>>

最佳答案

您将 Phalcon url 参数 attendancelist/search/attsearch/month/[monthValue] 与 GET 参数 (?month=[monthValue]) 混合在一起。

在 Phalcon 中,您必须设置路由器才能知道 url 的哪一部分是参数。

$router->add(
    "attendancelist/search/:action/month/{month}",
    array(
        "controller" => [your controller],
        "action"     => 1
    )
);

(有关更多信息,请参阅 the Phalcon Router docs)

然后在您的操作中,您必须从调度程序获取参数。

public function attsearchAction() {
    $month = $this->dispatch->getParam('month');
    var_dump($month);exit;
   }

public function attsearchAction($month) {
    var_dump($month);exit;
   }

关于javascript - 无法获取url参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32063103/

相关文章:

javascript - 如何将SVG对象的XY坐标中心转向平面中心?

javascript - VS2008 的 onerror 处理

javascript - Masonry 和 JQuery 重新加载

php - 搜索具有 2 个节点的父节点

php - 什么会导致双页请求?

javascript - 创建对话框时未捕获 TypeError : $(. ..).dialog 不是函数错误

javascript - script.readyState 在 IE11 和 FF 中未定义

javascript - RequireJS - 使用 2 个 jQuery 库

javascript - 在 JavaScript 或 jQuery 中,如何将 ontouchmove 事件转换为目标上的基本单击事件

javascript - 我无法使用 .load() jquery 返回上一页