【问题标题】:Phalcon PHP Range InputPhalcon PHP 范围输入
【发布时间】:2017-02-04 17:04:14
【问题描述】:

我正在尝试创建一个带有几个滑块的页面。当您更改这些滑块时,我想修改来自我的模型的数据并更新视图。

我知道你可以通过在常规 PHP 中使用 ajax 来解决这个问题。但我太缺乏经验,无法在 phalcon 框架内解决这个问题。 Phalcon\Forms 不支持 <input type="range" />。所以我在我的 volt 文件中添加了它:<input id="number_of_rooms" name="number_of_rooms" type="range" />.

我假设下一步是使用滑块事件处理程序创建一个JS 文件,该处理程序创建对我的控制器的 ajax 调用。我已经创建了事件处理程序,但是如何处理 ajax 调用给我带来了麻烦。

$('#number_of_rooms').on("change mousemove", function() {
    // $.ajax({
    //     method: "POST",
    //     url: "controllers/IndexController.php",
    //     data: { value: this.value }
    // })
    console.log("value: " + this.value);
});

但是如何将这些数据返回到我的控制器以修改我的模型,我不知道。非常感谢您的帮助。

如果我完全错误地处理这个问题,请告诉我。谢谢!

【问题讨论】:

    标签: jquery phalcon


    【解决方案1】:
        $.ajax({
            type:'POST',
            url: "{{ url() }}/your_path", (you create this path in file route)
            data: { value: this.value },
            async: false,
            dataType: "json",
            success:function(result){
                // the result will return from the controller
                // use the result to update your modal content
    
            },
            error: function(){
                // got error from controller
                // Do something 
            }
        });
    

    在你的路线中

    $backend->addPost('/your_path', array(
        'controller' => 'yourcontroller',
        'action' => 'yourmethod'
    ));
    

    不要忘记创建你的控制器控制器并在那里添加你的方法

    希望有帮助

    【讨论】:

      【解决方案2】:

      由于您通过 ajax 发送数据,因此 POST 数据将是 json 格式,您可以使用 this->request->getPost() 捕获它并将其传递给您的 getPost() 处理程序进行修改。例如返回的数据将是value: val,然后在您的控制器中使用$variable = $this->request->getPost('value') 捕获它

      【讨论】:

        猜你喜欢
        • 2021-08-22
        • 2015-01-19
        • 1970-01-01
        • 2012-04-17
        • 2019-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多