[英]Jquery ajax post only works once
我有一个发布值的jQuery脚本:
// //Delete a product from the shopping cart
tpj('.remove').on('click', function() {
// Stop form from submitting normally
event.preventDefault();
// Get some values from elements on the page:
console.log('test');
var $remove = tpj(this).attr('id');
url = 'includes/shoppingcart.php';
// Send the data using post
var posting = tpj.post( url, { remove: $remove} );
// Put the results in a div
posting.done(function( data ) {
var content = tpj( data );
tpj( "#result" ).empty().append( content );
});
});
第一次有效,但是当我第二次单击时,我重定向到我的主页,这很有意义,因为.remove
类所在的锚标记在href中没有任何内容。 但是,这意味着preventdefault()
不起作用,整个单击时不起作用。
这是为什么? 我用Google搜索,发现了我应该使用.on
代替.click
,但这并没有为我改变什么。
以下html行(触发jquery):
<a href="" class="remove" id="'.$cartproduct['product'].'" title="Verwijder product">×</a>
在我的header.php和shoppingcart.php
,当进行ajax发布并且将shoppingcart.php
的结果加载到我的购物车中时,该链接将停止运行,应有的状态。
我需要做什么?
功能(事件)进入
tpj('.remove').on('click', function() { //... } must be: tpj('.remove').on('click', function(event) { //... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.