嗨,我有一个手推车,我想要自动添加一个表单,这段代码似乎有点效果,但问题是,我必须点击F5为它添加的数量,我是非常新的,我不知道我哪里出了问题。
<form method="post" action="level3.php" class="jcart" id="foo">
<fieldset>
<input type="hidden" name="jcartToken" value="<?php echo $_SESSION['jcartToken'];?>" />
<input type="hidden" name="my-item-id" value="ABC-8" />
<input type="hidden" name="my-item-name" value="Level 1" />
<input type="hidden" name="my-item-price" value="95.00" />
<input type="hidden" name="my-item-url" value="" />
<table>
<tr>
<td width="65%">
<strong>Level 1 all for £95</strong>
</td>
<td width="15%" align="right">
£95.00
</td>
<td>
<input type="text" hidden ="true" name="my-item-qty" value="1" size="3" hidden="true" />
</td>
<td width="20%" align="center">
<input type="submit" name="my-add-button" id="my-add-button" value="add" class="button" />
</td>
</tr>
</table>
<input type="hidden" name="visited" value="" />
</fieldset>
这是将金额提交到结帐中的表单。
<script>
$(document).ready(function(){
//Check if the current URL contains '#'
if(document.URL.indexOf("#")==-1)
{
url = document.URL+"#";
location = "#";
} else {
location.reload(true);
document.getElementById("my-add-button").click();// Simulates button click this has to be in as it links to another piece of java that adds the item to the check out with out this it wont add the item
document.foo.submit(); // Submits the form without the button
}
});
</script>
document.getElementById("my-add-button").click();上面的代码链接到下面的代码,这些代码添加了我所知道的项目。
$('.jcart').submit(function(e) {
add($(this));
e.preventDefault();
});谢谢您的帮助或建议。
发布于 2014-06-02 09:50:16
如果我正确理解,您会在PHP中增加cart的一些值,而不是想要在页面上更新数量而不刷新页面。
我做了小JSFiddle:http://jsfiddle.net/7SbBA/
基本上使用ajax:
$.ajax({
url: 'example.com',
data: /* pass product id here */
success: function(){
/* update quantity you want */
}
}); 也有一些html更改。
更新
如果您想要更新页面加载上的总值,只需使用£<span class='amount'><?php echo $product['quantity'] * $product['price'] ?></span>,并且不需要使用jquery/js。但是,如果您仍然希望在加载窗口时动态更新,我更新了我的JSFiddle v.2
https://stackoverflow.com/questions/23990598
复制相似问题