在codeigniter jquery + ajax书签功能中停止页面加载 [英] stop page load in codeigniter jquery + ajax bookmark function
本文介绍了在codeigniter jquery + ajax书签功能中停止页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用书签功能(codeigniter,jquery,ajax).下面是表单的HTML和jQuery代码.
I'm working on a bookmarking function (codeigniter, jquery, ajax). Below is the HTML for the form and the jQuery code.
正在发生的事情:
- 表单正在将数据提交到数据库
- 页面正在重新加载
- 我没有收到成功警报
- 如果我使用e.preventDefault()或返回false,则不会重新加载页面,并且会收到成功警报,但是传递给数据库的数据为0.
HTML表单
<?php echo form_open('bookmarks/addBookmark'); ?>
<?php echo form_hidden('bookn', $bname); ?>
<?php echo form_hidden('booki', $this->uri->segment(4, 0)); ?>
<button class="bb_button">Bookmark</button>
<?php echo form_close(); ?>
jQuery
$('.bb_button').click(function() {
$.ajax({
url: 'bookmarks/addBookmark',
type: 'POST',
success: function (result) {
alert("Your bookmark has been added.");
}
});
//return false<--this is where I used it
});
推荐答案
您没有传入任何数据.
尝试
$('.bb_button').click(function(e) {
$.ajax({
url: 'bookmarks/addBookmark',
type: 'POST',
data: { bookn: $("[name='bookn']").val(), booki: $("[name='booki']").val() },
success: function (result) {
alert("Your bookmark has been added.");
}
});
e.preventDefault();
});
这篇关于在codeigniter jquery + ajax书签功能中停止页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文