Back to Top

Opencart Ajax

Updated 31 May 2016

Opencart Ajax – Using Ajax we can call our controller function and load data without refreshing page.For this we have to create a function in our controller file like and you can call it using ajax.

//in your controller file your ajax function
public function Ajaxcall(){

$this->load->model('module/wkajax_demo');
$this->language->load('module/wkajax_demo');

$json = array();
if(isset($this->request->post['call']) AND isset($this->request->post['data'])){

$data = $this->request->post['data'];
$call= $this->request->post['call'];
$result = $this->model_module_wkajax_demo->yourModelFunction($data,$call);

$json['success'] = $text_main;

}

$this->response->setOutput(json_encode($json));

}

//in your .tpl file after any event use ajax to call controller function
$.ajax({

type: 'post',
url: 'index.php?route=module/wkajax_demo/Ajaxcall',
//add data like this using &
data: 'call='+Ajax+'&data='+YourData,
dataType: 'json',
success: function(json) {
if(json['success']) {
//you can use data according to need
console.log(json['success']);
}else{
alert('error');
}
}
});

Searching for an experienced
Opencart Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


4 comments

  • Su Ahmed
    • Nikhil Chaudhary
      • Su Ahmed
        • Vikhyat Sharma
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home