I decided to create a quick product review in opencart, but stuck on ajax.
At first, I did not use dataType: 'json' and in return I received a whole page of the product, despite the fact that the controller method was empty.
Seias added dataType: 'json' and echo json_encode(array('result' => 'yes')); - returns an error with the contents of the Ошибка[object Object]
var fast_review={ "show": function function_name (product_id) { jQuery.ajax({ method:"POST", url: "/catalog/controller/extension/module/fast-review/get_product&product_id="+product_id, dataType: 'json', data: {id: product_id } }) .done(function( msg ) { alert( msg); $('.modal-fast-review').html(msg).modal().append('<button type="submit" class="btn btn-danger btn-default" data-dismiss="modal"><span></span>Зарыть</button>'); }) .fail(function( msg ) { alert("Ошибка"+msg); }); } } <?php class ControllerProductProduct extends Controller{ private function get_product(){ echo json_encode(array('result' => 'yes')); $this->load->model('catalog/product'); $this->getProduct((int)$this->request->get['product_id']); //var_dump($heading_title);//$_POST[id] //$this->model_catalog_product->getProduct((int)$this->request->get['product_id'])) //$this->response->setOutput("das"); } } ?>
JSON.parse(msg)as comrade specified above - ddeadlink