Php Prestashop 1.7控制器中的多个ajax动作函数

Php Prestashop 1.7控制器中的多个ajax动作函数,php,jquery,ajax,prestashop,prestashop-1.7,Php,Jquery,Ajax,Prestashop,Prestashop 1.7,我有一个javascript文件,在不同的按钮上有两个ajax调用。我有一个控制器Auction.php,其中有showPopup和askBidControl两个函数,但是对于第二个函数,ajax返回404 not found。它甚至没有进入initContent函数。以下是代码示例: class askbidAuctionModuleFrontController extends ProductControllerCore { public function initContent

我有一个javascript文件,在不同的按钮上有两个ajax调用。我有一个控制器Auction.php,其中有showPopup和askBidControl两个函数,但是对于第二个函数,ajax返回404 not found。它甚至没有进入initContent函数。以下是代码示例:

 class askbidAuctionModuleFrontController extends ProductControllerCore {

    public function initContent(){
        $this->ajax = true;
        parent::initContent();
    }

    public function displayAjaxShowPopup(){
        $type = Tools::getValue('type');
        switch($type){
            case 'bid':

                break;
            case 'ask':

                break;
            default:
                return false;
        }
        $product = $this->getTemplateVarProduct();
        ob_end_clean();
        header('Content-Type: application/json');

        $tpl = _PS_MODULE_DIR_.'askbid/views/templates/front/productPopUp.tpl';
        $this->context->smarty->assign('product', $product);
        $this->context->smarty->assign('type', $type);
        $html = $this->context->smarty->fetch($tpl);
        $this->ajaxDie(Tools::jsonEncode([
            'askbid_popup' => $html,
            'product' => $product,
        ]));
    }

    public function displayAjaxAskBidControl(){
        $type = Tools::getValue('type');
        $price = Tools::getValue('price');
        ob_end_clean();
        header('Content-Type: application/json');
        die('saracie');
//        $this->ajaxDie(Tools::jsonEncode(['trafalet']));
    }

}
JS:

productPopUp.tpl位于视图/模板/前端/

我不知道如何让第二个ajax调用工作。它只给出了404错误


更新:在第二个ajax请求askBidController上,它似乎甚至没有通过Auction.php的initContent函数,它有两个调用,一个调用我在ajax中的url,返回302 find,另一个对index.php?controller=404的调用。

PrestaShop控制器的ajax方法需要使用操作参数调用精确的语法:

displayAjax+myCustomAction

就你而言: 公共函数displayaxaskbidcontrol{} 应该有效

注意: 模块控制器应该扩展ModuleFrontController类,而不是其他控制器


在您的案例中,在第一个ajax调用中,您将id_产品作为参数,因此父控制器执行initContent方法,在第二个调用中,productController找不到id_产品,因此它会重定向它给出相同的错误。似乎在第二个ajax请求上它甚至没有通过initContent函数。两个请求的URL都是//localhost:8888/rarehouse/en/module/askbid/auction smm。。。你能试着在其他地方更改方法名吗?与displayAjaxMyAction类似,显然在myAction中的ajax调用中更改了param操作。我猜PS不喜欢方法中名为模块的部分…我已经尝试过多次了。同样的错误。它甚至不能通过initContent来访问我的函数。它要么找不到控制器要么。。。我不知道。抱歉,但直到现在我才注意到您正在扩展ProductControllerCore,为什么?该控制器应该扩展ModuleFrontrolleryEAH,但我需要使用ProductController的getTemplateVarProduct,当我尝试访问它们时,它不起作用。是的,我猜:,初始化ProductController,然后调用该方法,这是公开的,您需要一个ID产品作为var在post或GET中。问题是您已经扩展了productcontroller,它需要ID_产品,否则它将重定向到404I。我已尝试再次扩展ModuleFrontController,并且:$pc=new ProductControllerCore$product=$pc->getTemplateVarProduct;但它不起作用。init函数不接受参数。
$(document).ready(function(){
    $('.askBidButton').on('click', function () {
        let buttons_container = $("#askbid_buttons");
        let data = {
            'action': 'showPopup',
            'id_product': buttons_container.data('id-product'),
            'id_product_attribute': buttons_container.data('id-product-attribute'),
            'type': $(this).val()
        };
        let url = buttons_container.data('popup-url');
        $.post(url, data, null, 'json').then(function (resp) {
            $('body').append(resp.askbid_popup);
            let productModal = $(`#bidask-modal-${resp.product.id}-${resp.product.id_product_attribute}`);
            productModal.modal('show');
            productConfig(productModal);
            productModal.on('hidden.bs.modal', function () {
                productModal.remove();
            });
        }).fail((resp) => {
            prestashop.emit('handleError', {eventType: 'clickQuickView', resp: resp});
        });
        return false;
    });
    $('body').delegate('#continue_place_askbid', 'click', function(e){
       let type = $(this).val();
       let price = $(this).parent().find('#askbid_price_input').val();
       let data = {
           'action':'askBidControl',
           'type': type,
           'price': price
       };
       let url = $(this).closest('.quickview').data('popup-url');
       console.log(url);
       console.log('trafalet');
       $.ajax({
           url: url,
           data: data,
           success: function(resp){
               console.log('trafaleteeeee');
           },
           error: function(err){
               console.log(err);
           }
       });
       return false;
    });