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
source share