jQuery AJAX$.post无法使用.click()方法
jQuery AJAX $.post not working with .click() method
我的ajax请求有点困难。$.post方法似乎根本不起作用,没有发送任何请求。萤火虫也没什么表现。
我可以让这个工作:
$('.comment-remove').click(function (evt) {
evt.preventDefault();
var sure = confirm('Are you sure your want to remove your comment from this thread?');
if(sure) {
var comment_id = $(this).attr('id');
alert(member_id);
}
});
但不是这个:
$('.comment-remove').click(function (evt) {
evt.preventDefault();
var sure = confirm('Are you sure your want to remove your comment from this thread?');
if(sure) {
var comment_id = $(this).attr('id');
$.post('comment.php', { comment_id: comment_id }, function(data) {
if (data === 'success') {
alert(data);
} else {
alert('Unable to remove comment at this time.');
}
}
}
});
HTML是:
<a class="comment-remove" id="<?php echo $comment_id; ?>">Remove my comment</a>
应该是:
$.post('comment.php', { comment_id: comment_id }, function(data) {
if (data === 'success') {
alert(data);
} else {
alert('Unable to remove comment at this time.');
}
})
看到我添加的额外)
了吗?它在开始时与$.post(
中的(
相匹配。你错过了,这总是很容易做到的。你的控制台应该能够告诉你这类事情。
您的post调用缺少一个右括号。试试这个:
$('.comment-remove').click(function (evt) {
evt.preventDefault();
var sure = confirm('Are you sure your want to remove your comment from this thread?');
if(sure) {
var comment_id = $(this).attr('id');
$.post('comment.php', { comment_id: comment_id }, function(data) {
if (data === 'success') {
alert(data);
} else {
alert('Unable to remove comment at this time.');
}
})
}
});
相关文章:
- 使用click()方法是在创建一个无休止的循环
- jQuery AJAX$.post无法使用.click()方法
- 有没有一种不那么黑客的方法可以防止我的 on('click') 触发两次
- Vue.js 使用 Vuex 和自定义组件,@click方法输出未定义
- Jquery change() 方法在 click(x+2) 上重复
- ng-click 或 ng-submit 不调用控制器方法
- casperjs,可能需要另一个click方法
- UFT在使用Web加载项时如何执行Click方法
- javascript click()方法的问题/ html
- 即使元素被禁用,selenium click()方法也能工作吗?
- 使用click()方法使用隐藏的文件输入元素
- 当动态创建时,Click()方法不会触发锚上的Click事件
- 我想从jQuery.click()方法传递一个参数
- 使用 Click 方法导入所有 XML 属性值
- 将多个参数传递给 ng-click 方法
- Javascript:使用.click方法时出现问题
- Jquery .click方法失败
- Javascript .click()方法在某些情况下不能在android上工作
- 调用controlgroup .click()方法
- 在click方法内绑定事件