나는 자바 스크립트 파일을 가지고 있고 다른 버튼에는 두 개의 아약스 호출이있다. 나는 두 개의 액션 (showPopup과 askBidControl)을위한 함수를 가지고있는 컨트롤러 인 Auction.php를 가지고 있지만, 두 번째 함수의 경우 ajax는 404를 찾을 수 없다. 그것은 심지어 initContent 함수를 입력하지 않습니다.Prestashop 1.7 컨트롤러에서 여러 개의 아약스 액션 함수들
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 :
$(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;
});
productPopUp.tpl이 뷰/템플릿/앞에/
내가 방법을 정확히 모르는 여기에 코드의 샘플입니다 두 번째 아약스 콜 작업을합니다. 그냥 404 오류를 제공합니다.
업데이트 : 두 번째 ajax 요청 (askBidController)에서 Auction.php의 initContent 함수를 통과하지도 않는 것 같아요. 그리고 두 번의 호출이 있습니다. 하나는 ajax에있는 URL에 대한 것이고 302는 찾은 것입니다. index.php? controller = 404에 대한 또 다른 호출.)
public function displayAjaxAskBidControl(){}
해야 작품 : 귀하의 경우
displayAjax
+ myCustomAction
:
죄송 리디렉션하도록 id_product를 검색 할 수 없습니다 productController 부르지 만, 지금은'ProductControllerCore'를 확장하고 있다는 것을 알아 차 렸습니다. 왜? 그 컨트롤러는 ModuleFrontController를 확장해야합니다 – sarcom
그래,하지만 ProductController의 getTemplateVarProduct를 사용할 필요가 있었고 액세스하려고 시도했을 때 작동하지 않았다. – Ciubakka
네, 짐작했는데 :) productController를 초기화하고 메서드를 호출하면 public이됩니다. (ID 제품이 필요합니다 (게시 또는 가져 오기에서 var로 사용)) – sarcom