我遇到了Ajax和CodeIgniter购物车的问题。没有AJAX,代码运行良好。好像我无法发帖。
<script type="text/javascript">
$('ul.products form').submit(function(){
$('#noticeMessages').empty();
var id = $(this).find('input[name=id]').val();
$.ajax({
type: 'post',
url:'../books/addProduct',
data:{id:id}
}).done(function(data){
$('#noticeMessages').append('Your product has been added').css('visibility','visible').fadeIn('fast').fadeOut(5000);
location.reload();
});
return false;
});
</script>
答案 0 :(得分:0)
虽然这似乎是一个死的问题,但我仍然觉得提出我的建议。这就是我要做的事情
<script type="text/javascript">
$('ul.products form').submit(function(){
$('#noticeMessages').empty();
var id = $(this).find('input[name=id]').val();
$.ajax({
type: 'post',
url:'../books/addProduct',
data:{id:id},
success:function(data){
$('#noticeMessages').append('Your product has been added').css('visibility','visible').fadeIn('fast').fadeOut(5000);
location.reload();
}
});
});
</script