我有一個Codeingiter應用程序,使用jquery將帖子保存到數據庫中!但問題是它存儲兩次相同的數據!我審查了代碼,但我似乎無法弄清楚!請幫幫我! 查看:codeigniter兩次保存帖子
<div id="poster">
<label id="poster_label" > State your feeling.. </label> <br />
<textarea rows="3" cols="60" id="poster_textarea" ></textarea> <br />
<input type="button" id="poster_button" value="Publish" />
</div>
JS:
$('#poster_button').click(function(){
if(!$('#poster_textarea').val()){
$('#poster_textarea').css('border','1px solid pink').focus();
return false;
}else{
var poster_textarea = $('#poster_textarea').val();
var url = "<?php echo base_url();?>index.php/blog/add_post";
$.ajax({
type: "POST",
url: url,
data: 'poster_textarea='+poster_textarea,
//datatype: "json",
success: function()
{
alert('saved');
}
});
}
});
控制器:
function add_post(){
$post_data = array(
'id' => '',
'user_id' => '11330',
'content' => $this->input->post('poster_textarea'),
'date_time' => date("Y-m-d H:i:s"),
'status' => '1'
);
$this->blog_model->add_post($post_data);
}
型號:
function add_post($post_data){
$this->db->trans_start();
$this->db->insert('posts',$post_data);
$this->db->trans_complete();
}
那麼你需要點擊Net標籤並提交表格,檢查多少職位都發給。 – 2013-05-08 06:11:53
@Syed Haider Hassan:當然,它發送兩個帖子..它顯示在螢火蟲!但爲什麼應該發佈兩個? – goseo 2013-05-08 06:14:49