开发者

opencart - mvc - jquery / call function without reload

I've been working on a script on opencart that uses jquery $.post .

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

In opencart i've created a function in the model that contains what should be in updateDB.php I was hoping to get this function to be called instead of an external page(updateDB.php) and without reloading the current page.

Maybe .post is not the one i should use or is it?

Any idea would be appreciated.


Not sure exactly what you are trying here, but personally I use $.getJSON when making requests to opencart.

To use OC's models etc, you will need to create a controller file to access it. For example, if you want to use common/update as your route, you could create the file

/catalog/controller/common/update.php

Then in there, you would have

<?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
    }
}

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜