开发者

Paypal "add to cart" without leaving page

开发者 https://www.devze.com 2023-04-03 23:52 出处:网络
I am trying to integrate a paypal add to cart button on my page. When added per paypal the form included seems to work fine .. but when I use ajax to serialize and submit the form it gives me a 302 er

I am trying to integrate a paypal add to cart button on my page. When added per paypal the form included seems to work fine .. but when I use ajax to serialize and submit the form it gives me a 302 error and never populates the Div.

Technically I am trying ot avoid reloading the page, or redirecting/opening a new page when someone clicks the "add to cart" button, and figured i could work around this with Ajax. Apparently a redirect kills that possiblity as the ajax call can't post or load the redirected page?

Any pointers would be apprecaited.

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="b开发者_如何转开发usiness" 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


You can use the add="1" method of the Shopping Cart API to submit multiple items. All you need to do is to include the item_name, item_number and/or amount variables for each product you want to submit, like this.

<!-- 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 check HTML Variables for PayPal Payments Standard for more information regarding this API method and the variables you can use.


I have individual buttons for add to cart, and need this process to add multiple items as additionally well.

I did find that you can use a form to submit multiple items using the "upload='1'" method, but when submitted it "overwrites" the current cart items with the newlist ... which won't work as the other items i input with the single "add to cart" button will be lost.

Has anyone had any experience with this? I was hoping that paypal hd an API i could add items with .. but have been unable to find anything like that.

0

精彩评论

暂无评论...
验证码 换一张
取 消