vscorpion Posted February 11, 2014 Share Posted February 11, 2014 (edited) Здравствуйте. Подскажите, как сделать ajax запрос для тега a в prestashop 1.5? Создал в модуле свой контроллер он все обрабатывает, но страница грузится с белой страницей. как сделать так чтобы страница не перезагружалась, а просто обработался запрос? <a class="rate-link like" href="{$link->getModuleLink('vlproductlike', null, ['process' => 'like', 'id_product' => {$id_product}])}"></a><span class="count positive">{$rate_ok}</span> class VLProductLikeDefaultModuleFrontController extends ModuleFrontController{public function postProcess(){switch(Tools::getValue('process')){case 'like':$this->ajaxProcessVote('like');break;case 'dislike':$this->ajaxProcessVote('dislike');break;}}protected function ajaxProcessVote($param = null){$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT rate_ok,rate_badFROM '._DB_PREFIX_.'vlproductlikeWHERE id_product = '.(int)Tools::getValue('id_product'));if ($param == 'like') {if ($result)Db::getInstance()->execute("UPDATE "._DB_PREFIX_."vlproductlike SET rate_ok = rate_ok + 1 WHERE id_product=".(int)Tools::getValue('id_product'));// Db::getInstance()->execute("UPDATE "._DB_PREFIX_."vlproductlike SET rate_bad = rate_bad - 1 WHERE id_product=".$this->id_product." AND rate_bad > 0");elseDb::getInstance()->execute("INSERT INTO "._DB_PREFIX_."vlproductlike (id_product,rate_ok) VALUES (".(int)Tools::getValue('id_product').",1)");die(0);}else if ($param == 'dislike') {if ($result)Db::getInstance()->execute("UPDATE "._DB_PREFIX_."vlproductlike SET rate_bad = rate_bad + 1 WHERE id_product=".(int)Tools::getValue('id_product'));// Db::getInstance()->execute("UPDATE "._DB_PREFIX_."vlproductlike SET rate_ok = rate_ok - 1 WHERE id_product=".$this->id_product." AND rate_ok > 0");elseDb::getInstance()->execute("INSERT INTO "._DB_PREFIX_."vlproductlike (id_product,rate_bad) VALUES (".(int)Tools::getValue('id_product').",1)");die(0);}die(1);}} Edited February 11, 2014 by vscorpion (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts