Paypal "add to cart" without leaving the page

I am trying to integrate the Paypal add to cart button on my page. When added to paypal, the included form works fine. But when I use ajax to serialize and submit the form, it gives me a 302 error and never fills the Div.

Technically, I try not to reload the page or redirect / open a new page when someone clicks the "add to cart" button, and decided that I can get around this with Ajax. Apparently redirecting kills this possibility since ajax call cannot publish or load the redirected page?

Any pointers would be appreciated.

Here is my code:

JavaScript:

$(document).ready(function(){ $(".addToCart").click(function(){ var ev = arguments[0] || window.event, origEl = ev.target || ev.srcElement; var cartForm = origEl.name; var formData = $(cartForm).serialize(); $.ajax({ type: "POST", url: "https://www.paypal.com/cgi-bin/webscr", cache: false, data: formData, success: onSuccess, error: onError }); return false; }); }); 

HTML:

 <a class="addToCart" cartNumber="#paypal<?PHP echo $counter; ?>"> <img name="#paypal<?PHP echo $counter; ?>" src="images/butNowButton.jpg" cartNumber="#paypal<?PHP echo $counter; ?>" border="0" style="text-decoration:none;" /> </a> <form name="paypal<?PHP echo $counter; ?>" id="paypal<?PHP echo $counter; ?>" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="business" value="removed for security"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="item_name" value="<?PHP echo $itemName; ?>"> <input type="hidden" name="item_number" value="<?PHP echo $Row['id']; ?>"> <input type="hidden" name="amount" value="<?PHP echo $amount; ?>"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="button_subtype" value="products"> <input type="hidden" name="no_note" value="0"> <input type="hidden" name="tax_rate" value="0.000"> <input type="hidden" name="shipping" value="0.00"> <input type="hidden" name="add" value="1"> <input type="hidden" name="bn" value="PP-hopCartBF:btn_cart_LG.gif:NonHostedGuest"> </form> 

thanks,

Silver tiger

+4
source share
2 answers

You can use the add="1" shopping cart API method to submit multiple items. All you have to do is include the variable item_name , item_number and / or amount for each product that you want to send, for example.

 <!-- item 1 --> <input type="hidden" name="item_name_1" value="...."> <input type="hidden" name="item_number_1" value="...."> <input type="hidden" name="amount_1" value="...."> <!-- item 2 --> <input type="hidden" name="item_name_2" value="...."> <input type="hidden" name="item_number_2" value="...."> <input type="hidden" name="amount_2" value="...."> <!-- item x --> <input type="hidden" name="item_name_x" value="...."> <input type="hidden" name="item_number_x" value="...."> <input type="hidden" name="amount_x" value="...."> 

Please review the HTML variables for the PayPal Payments standard for more information about this API method and the variables you can use.

+1
source

I have separate buttons for adding to the cart, and this process needs to be added in order to add several elements as best as possible.

I found that you can use the form to submit multiple items using the "upload = '1" method, but when transferred it "overwrites" the current position of the cart with a new list ... which will not work like other items entered using the button "add to cart" will be lost.

Does anyone have any experience? I was hoping that the paypal hd API, I could add elements with .., but could not find anything like it.

0
source

All Articles