Post by Uncle_Pasha » Tue May 31, 2016 9:26 pm

Hello.
I am a newbie in Opencart. I'm trying to develop a custom module that gets the list of categories and when i select one of them, it displays the list of products for this category. I'm trying to do it via AJAX get request but i have some problems with id.

AJAX function in .tpl file

Code: Select all

<script>
     $('#category').on('change', function() { //#category is an id for <select> list with categories
            $.ajax({
                method: 'GET',
                url: 'index.php?route=module/my_module&category_id='+this.value, //here i set up a url to controller and parameter for get query

            }).done(function(data, Status){

            });
      });
</script>
Code from the controller:

Code: Select all

$this->load->model('catalog/product');
        $category_id = $this->request->get['category_id']; //here i try to catch the get data but it can't
        $this->data['product'] = $this->model_catalog_product->getProductsByCategoryId($category_id);

        $this->response->setOutput();
I can't get any data from 'get' query, and it's the main problem. I saw that the AJAX query is formed well (in Google Chrome web tools), but it seems that it doesn't come to a controller. What am i doing wrong?

Thank you in advance.

Newbie

Posts

Joined
Tue May 31, 2016 8:44 pm

Post by inactiveaccount9912 » Fri Jun 03, 2016 7:59 pm

use success option for ajax like all the ajax calls in opencart do.
As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success(). => http://api.jquery.com/jquery.ajax/

Expert Member

Posts

Joined
Fri May 14, 2010 2:36 am
Who is online

Users browsing this forum: No registered users and 2 guests