我試圖爲我的Magento商店之一運行以下jquery ajaxSubmit。我使用ajaxSubmit,因爲我也有2個文件要從表單上傳(也就是說我需要$_FILE
中的數據)。但是當我執行ajaxSubmit時,它也會使用正常的表單提交,它會刷新頁面並將我帶到下一頁,而不是留在同一頁面上,其中有一個彈出框,其中包含更多內容。我有return false;
以防止這種情況,但它失敗。 的提交代碼:jquery ajaxSubmit也提交了常規表格
$('#quickbuyform').submit(function(){
// No Accessories: normal submit
if ($('#accessories ul li').size()==0) {
return true;
}
strName = "<?php echo $_product->getName() ?>";
// loading message
$('#pop_accessories_area_message').html("We are adding '"+strName+"' into your shopping cart ...");
// Pop with loading
popAccessories();
// loading icon
//var dataString = $('#quickbuyform').serialize();
$.ajaxSubmit({
type: "POST",
url: $('#quickbuyform').attr('action'),
data: dataString,
beforeSubmit: showRequest,
success: function() {
// display cart link:
$('#pop_accessories_area_message').html(strName+" was added to <a href='<?php echo $this->getUrl('checkout/cart') ?>'>your shopping cart</a>.");
$('.pop_accessories_area_button').show();
//window.location = '<?php //echo $this->getUrl('checkout/cart') ?>';
}
});
return false;
});
因此,這是我現在有e.preventDefault()
,但現在不提交任何東西。僅僅停留在('#quickbuyform').ajaxSubmit
$('#quickbuyform').submit(function (e){
e.preventDefault();
// No Accessories: normal submit
if ($('#accessories ul li').size()==0) {
return true;
}
strName = "<?php echo $_product->getName() ?>";
// loading message
$('#pop_accessories_area_message').html("We are adding '"+strName+"' into your shopping cart ...");
// Pop with loading
popAccessories();
$('#quickbuyform').ajaxSubmit({
type: "POST",
url: $('#quickbuyform').attr('action'),
data: dataString,
success: function() {
// display cart link:
$('#pop_accessories_area_message').html(strName+" was added to <a href='<?php echo $this->getUrl('checkout/cart') ?>'>your shopping cart</a>.");
$('.pop_accessories_area_button').show();
//window.location = '<?php echo $this->getUrl('checkout/cart') ?>';
}
});
return false;
});
如果表單的action屬性中包含正確的url,則不需要指定url選項,默認情況下,ajaxSubmit將使用此選項。 –