codeigniter jquery表单提交
大家好,我的表单似乎与提交和jquery一样工作正常,尽管有两件事:它似乎没有把信息传递出去,因为它不断添加0、0、0,而不是我在表单中提交的内容。下一步它不刷新页面后?也许jquery缺少什么 在模型中插入函数:codeigniter jquery表单提交,jquery,codeigniter,Jquery,Codeigniter,大家好,我的表单似乎与提交和jquery一样工作正常,尽管有两件事:它似乎没有把信息传递出去,因为它不断添加0、0、0,而不是我在表单中提交的内容。下一步它不刷新页面后?也许jquery缺少什么 在模型中插入函数: function entry_insert(){ $this->load->helper('form'); $this->load->helper('html'); $this->load->database()
function entry_insert(){
$this->load->helper('form');
$this->load->helper('html');
$this->load->database();
$data = array(
'title'=>$this->input->post('title'),
'url'=>$this->input->post('url'),
'jscore'=>$this->input->post('jscore'),
'kscore'=>$this->input->post('kscore')
);
$this->db->insert('movies',$data);
}
这是加载模型的jquery调用的控制器函数:
public function addmovie()
{
$this->load->model('Movie_model', '', TRUE);
$this->Movie_model->entry_insert();
return true;
}
视图中的html表单:
<form class="form-signin" method="post" id="form-signin">
<h4 class="form-signin-heading">Add a Movie</h4>
<input type="text" class="input-block-level" placeholder="Movie Title" id="title">
<input type="text" class="input-block-level" placeholder="URL" id="url">
<input type="number" class="" min="1" max="100" placeholder="Jamies Score" id="jscore">
<input type="number" class="" min="1" max="100" placeholder="Kellys Score" id="kscore">
<button class="btn btn-large btn-primary" type="submit">Add</button>
</form>
添加电影
添加
最后是jquery:
<script>
$(function(){
$("#form-signin").submit(function(){
dataString = $("#form-signin").serialize();
$.ajax({
type: "POST",
url: "http://xxx.com/xx/index.php/welcome/addmovie",
data: dataString,
success: function(data){
alert('Successful!');
}
});
return false; //stop the actual form post !important!
});
});
</script>
$(函数(){
$(“#表单签名”).submit(函数(){
dataString=$(“#表单签名”).serialize();
$.ajax({
类型:“POST”,
url:“http://xxx.com/xx/index.php/welcome/addmovie",
数据:dataString,
成功:功能(数据){
警报(“成功!”);
}
});
return false;//停止实际表单发布!重要信息!
});
});
谁能看出我做错了什么?也许可以帮助我的jquery刷新?您的输入没有读取服务器端值所需的
name
属性,并且您的serialize()
调用可能也没有返回任何内容。我猜你认为这就是id的作用,但事实并非如此
例如:
<input placeholder="Kellys Score" id="kscore">
应该是:
<input placeholder="Kellys Score" name="kscore" id="kscore">
<!-- Needs this ^^^^^^^^^^^^^ -->
非常感谢!想不到,它马上就可以完美工作:)你有没有可能自动帮助刷新?我不知道你想“刷新”什么。success回调中的data
参数将有服务器的响应,因此可以随心所欲地使用它。让服务器返回javascript所需的任何内容,以执行您试图执行的任何操作。等等,如果之后重新加载整个页面,为什么要使用ajax提交表单?这不就是不使用ajax吗?