我有一个页面,用户可以在其中撰写有关某些网站的评论。我需要将此数据发布到我的 Codeigniter 控制器,该控制器使用模型函数将数据插入数据库。在我添加 jquery 之前一切正常,现在它没有发布,而且似乎根本没有进入控制器。任何解决此问题的帮助将不胜感激。谢谢。
html
<table id="revForm">
<tr>
<td>Site reviewed:</td>
<td><input readonly type="text" id="site" name="profile" value="<?php echo $sitename; ?>"></td>
</tr>
<tr>
<td>Name:</td>
<td> <input type="text" id="name" name="name" value="Enter name"> </td>
</tr>
<tr>
<td>Message:</td>
<td><textarea row="6" column="40" id="message" name="message" value="message"></textarea></td>
</tr>
<tr>
<td>Rate this site</td>
<td>
<div>
<input name="rating" type="radio" value="1" class="star"/>
<input name="rating" type="radio" value="2" class="star"/>
<input name="rating" type="radio" value="3" class="star"/>
<input name="rating" type="radio" value="4" class="star"/>
<input name="rating" type="radio" value="5" class="star"/>
</div>
</td>
</tr>
</table><br>
<button id="submitReview2">Submit</button><br/>
控制器“评论”
public function addReview() {
$this->load->helper('form');
if ($this->input->post("message")!="") {
$this->reviewsMod->addReview($this->input->post('profile'),
$this->input->post('name'),
$this->input->post('message'),
date('d/m/Y'),
$this->input->post('rating'));
$data['sitename'] = $this->input->post('profile');
$this->load->view('shared/header');
$this->load->view('profile', $data );
$this->load->view('shared/footer');
}
else {
$this->load->view('shared/header', $session);
$this->load->view('profile', $data);
$this->load->view('shared/footer');
}
}
jQuery
$('#submitReview2').click(function() {
var profile = $('#site').val();
var name = $('#name').val();
var message = $('#msg').val();
var rating = $('#rating').val();
var msgData = {
'profile':profile,
'name':name,
'message':message,
'rating':rating
}
var base_url = '<?php echo base_url(); ?>';
$.ajax ({
type: 'POST',
url: base_url+'reviews/addReview',
data: msgData,
success:
function(){
$('#revForm').html("<div id='success'></div>")
$('#success').html("Your review has been submitted")
.fadeIn(1500);
}
});
return false;
模型功能
public function addReview($profile, $name, $message, $stamp, $rating) {
$this->setValues($profile, $name, $message, $stamp, $rating);
$this->db->insert('messages', $this);
}