Paypal“添加到购物车”不离开页面
我正在尝试在我的页面上集成贝宝“添加到购物车”按钮。当每个 paypal 添加时,包含的表单似乎工作正常..但是当我使用 ajax 序列化并提交表单时,它给了我一个 302 错误并且从不填充 Div。
从技术上讲,我试图避免重新加载页面,或当有人单击“添加到购物车”按钮时重定向/打开新页面,并认为我可以使用 Ajax 解决此问题。显然,重定向会消除这种可能性,因为 ajax 调用无法发布或加载重定向页面?
任何指示将不胜感激。
这是我的代码:
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>
谢谢,
银虎
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="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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Shopping Cart API 的
add="1"
方法提交多个商品。您所需要做的就是为要提交的每个产品添加item_name
、item_number
和/或amount
变量,如下所示。请检查 PayPal 付款标准的 HTML 变量 有关此 API 方法和您可以使用的变量的更多信息。
You can use the
add="1"
method of the Shopping Cart API to submit multiple items. All you need to do is to include theitem_name
,item_number
and/oramount
variables for each product you want to submit, like this.Please check HTML Variables for PayPal Payments Standard for more information regarding this API method and the variables you can use.
我有用于添加到购物车的单独按钮,并且还需要此过程来添加多个项目。
我确实发现您可以使用表单使用“upload='1'”方法提交多个项目,但是提交时它会用新列表“覆盖”当前购物车项目...这不会像其他项目一样工作我使用单个“添加到购物车”按钮输入的内容将会丢失。
有人有这方面的经验吗?我希望 paypal hd 有一个 API,我可以用 .. 添加项目,但一直找不到类似的东西。
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.