Post by blackarch » Wed Feb 24, 2016 11:25 am

I try build a simple Ajax, It's simple just display data from db using ajax trigger of combo box(select 1-7) if select 1 in sql

Code: Select all

select * from table_name where menu = '1'; 
then show it.
I using onChange for combobox in javascript.
I already try in php with same database, and it's working. But when I try implement in open cart it's failed.
What i know problem is the url in ajax, because if i change code ajax. E.g change to alert it's working.

This for Ajax : ( I using jquery-1.7.1.min.js, already try with 1.9.1 too)

Code: Select all

$(document).ready(function() {
    $('#id_menu').change(function() {
        if ($(this).val != 0) {    // If I change with alert, it's working ( Delete $.AJAX)
          var menu_id = $(this).val();   // STORE variable menu (1-7) to menu_id
          $.ajax({
            type: "POST",
            url: "index.php?route=item/edit_item/function_menu",
            data: {
              menu_id: menu_id
            },
            dataType: "html",
            success: function(response) {
              $("#data-menu").html(response);
            }
          });
        }
      }).change();
    });
And this for CONTROLLER : (class ControllerItemEditItem extends Controller )

Code: Select all

public function function_menu()
{                     // FUNCTION AJAX
    echo "AAA";exit;    // TRY ECHO for checking it's work or not ,and it's not working :(
    $this->language->load('item/edit_item');
    $this->document->setTitle($this->language->get('heading_title')); 
    $this->load->model('item/edit_item');

    if(isset($this->request->post['menu_id']))
        $menu_id = $this->request->post['menu_id'];
    else
        $menu_id = null;

    $data = array(
        'menu'      =>$menu_id,
    );
    
}
And idkw why results like this :
http://s1064.photobucket.com/user/black ... sort=3&o=0

When i try change menu from "select menu" to 1-7,
it's display my home page again (repeated). ???

New member

Posts

Joined
Thu Jan 07, 2016 6:00 pm
Who is online

Users browsing this forum: No registered users and 45 guests