[英]pop-up window close with “add to cart” button
I'm trying to setup a shopping cart form function (add to cart button) which is called via JavaScript. 我正在尝试设置通过JavaScript调用的购物车表单功能(添加到购物车按钮)。 I have this in a pop-up window and want to have the "add to cart" button both close the pop-up window and also load the info in the main window.
我在弹出窗口中具有此功能,并且希望具有“添加到购物车”按钮既可以关闭弹出窗口,又可以在主窗口中加载信息。 Does anyone know what script modifications I need to have?
有谁知道我需要修改哪些脚本?
Here is my current code in the pop-up window to generate the add to cart: 这是我当前在弹出窗口中生成添加到购物车的代码:
<form class="cart" action="index-shop.php" method="post">
<input type="hidden" name="my-item-id" value="book 1" />
<input type="hidden" name="my-item-name" value="book 1" />
<input type="hidden" name="my-item-price" value="35.00" />
<input type="hidden" name="my-item-url" value="http://www.amazoni.com" />
Qty: <input type="text" name="my-item-qty" value="1" size="3" />
<input class="button" type="submit" name="my-add-button" value="add to cart" />
</form>
Ok, so assuming you've included the jquery file somewhere before this in you webpage, this is how I would go about solving the problem you're having; 好的,所以假设您已经将jquery文件包含在网页中的此位置之前,这就是我将如何解决您遇到的问题;
<form class="cart">
<input type="hidden" name="my-item-id" value="book 1" />
<input type="hidden" name="my-item-name" value="book 1" />
<input type="hidden" name="my-item-price" value="35.00" />
<input type="hidden" name="my-item-url" value="http://www.amazoni.com" />
Qty: <input type="text" name="my-item-qty" value="1" size="3" />
<input class="button" type="submit" id="my-add-button" name="my-add-button" value="add to cart" />
</form>
<script type="type/JavaScript">
$(document).ready(function(){
$(".cart").submit(function(e){
e.preventDefault(); //prevent the form from submitting
});
//send the form to the server mimicking the post behaviour, without submitting the form
$("#my-add-button").click(function(){
$.post("index-shop.php", $(".cart").serialize(), function(data){
if(data.success){ // this is assuming you created a variable indicating whether server processing succeeded
/*
* here we insert the post server processing code
* and then we close the dialog
*/
}else{
alert(data.error); //if there's an error we display the error message and keep the dialog window open allowing the user to continue
}
});
return false;
});
});
</script>
get back to me if you're having anymore problems or need a little more direction. 如果您遇到其他问题或需要更多指导,请与我联系。 I'm South African by the way;
我是南非人 and our time is 13:30 right now.
现在我们的时间是13:30 .
。 .about to go on my lunch break soon
。关于快去午休
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.