Opencart - MVC - jquery /调用函数无需重新加载


opencart - mvc - jquery / call function without reload

我一直在openart上使用jquery $编写脚本。职位。

$(document).ready(function() {
    $(function() {
        $("#contentLeft ul").sortable({
            opacity: 0.6,
            cursor: 'move',
            update: function() {
                var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
                $.post("updateDB.php", order, function(theResponse) {
                    $("#contentRight").html(theResponse);
                });
            }
        });

在openart中,我在模型中创建了一个函数,该函数包含updateDB.php中应该包含的内容我希望得到这个函数被调用,而不是一个外部页面(updateDB.php)并且无需重新加载当前页面。

也许。post不是我应该用的,是吗?

不确定您在这里尝试什么,但我个人在请求openart时使用$.getJSON

要使用OC的模型等,你需要创建一个控制器文件来访问它。例如,如果你想使用common/update作为你的路由,你可以创建文件

/目录/控制器/共同/update.php

然后是

<?php
class ControllerCommonUpdate extends Controller {
    public function index() {
        //Get "order" parameter
        $order = empty($this->request->get['order']) ? '' : $this->request->get['order'];
        // Load model
        $this->load->model('model/name');
        $result = $this->model_model_name->method($order);
        // Load JSON lib and output content here
    }
}
?>