Magento – Form per Ajax Request absenden

26. Juli 2010 at 18:12

Hier ein Beispiel (Produkt zum Warenkorb hinzufügen) zum absenden eines Form per Ajax Request in Magento:

<script type="text/javascript">
 //<![CDATA[
 var productAddToCartForm = new VarienForm('product_addtocart_form');
 productAddToCartForm.submit = function(product_name) {
 if (this.validator.validate()) {
new Ajax.Request($('product_addtocart_form').action, {
 parameters: Form.serialize($('product_addtocart_form'), true),
 area: $('product_addtocart_form'),
 onComplete: function (transport) { }
 });
}
 }.bind(productAddToCartForm);
 //]]>
</script>

Alternative Code aus dem Newsletter

<script type="text/javascript">
//<![CDATA[
function submitSubscribe() {
 new Ajax.Request('<?php echo Mage::getBaseUrl() ?>newsletter/subscriber/newajax/',
 {
 method:'post',
 parameters: $('newsletter-subscribe').serialize(true),
 onLoading: function(){
 $('subscribe_update_div').show();
 $('subscribe_update_div').innerHTML = "<?php echo $this->__('Sending subcribe request ...'); ?>";
 },
 onSuccess: function(transport){
 var response = transport.responseText.evalJSON();
 $('subscribe_update_div').innerHTML = response.message;
 },
 onFailure: function(){
 $('subscribe_update_div').innerHTML = "<?php echo $this->__('Something went wrong ...'); ?>";
 }
 });
 }
//]]>
</script>
GD Star Rating
loading...
GD Star Rating
loading...
Magento - Form per Ajax Request absenden, 10.0 out of 10 based on 1 rating