0

On the same page I have 2 sections. First section is generated dynamically (when I enter a text in an autocomplete field) and the second section is loaded on pageload.

There is an ajax all I need to make from both sections (basically add a product button is present in both sections).

jq.ajax({
      url: '<?php echo Mage::getBaseUrl(); ?>marketplace/product/addcart/',
      dataType: 'JSON',
      data: {"productid":product_id,"qty":product_qty,"customOption":customOption}, 
      success: function(result) {
                jq('.ajax_loader').hide();
                var cartdiv = result.cartsidebar;                     
                jq(".shoping-cart").html(cartdiv);
                jq.growl.notice({ message: result.message });

                              }

});

This call succeeds from the second section and works like a charm but when I make the same call from the first section (that was dynamically generated) then it fails and xrs.status is 0

I have checked in firebug and the url is resolving exactly the same in both sections:

GET http://localhost/magentonew/marketplace/product/addcart/?productid=5666&qty=1

What am I doing wrong?

1 Answer 1

0

Most probably you are missing the form key.
Try to make the data option for the ajax call look like this:

{"productid":product_id,"qty":product_qty,"customOption":customOption,"form_key":FORM_KEY}
1
  • sorry did not work... i added var FORM_KEY = '<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>'; and then your code Commented Oct 27, 2015 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.