Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DOC

Opencart Ajax

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');
}
}
});
. . .

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