我的ajax脚本是
<script>
$(document).ready(function(){
$('form.tg-form-signup').on('submit',function(form){
form.preventDefault();
$.post('Comeon/sm',$('form.tg-form-signup').serialize(),function(data){
$('div.jsError').html(data);
});
});
});
</script>
$this->load->library('form_validation');
$this->form_validation->set_rules('mobile_number', 'mobile_number', 'trim|required|exact_length[10]|numeric');
$this->form_validation->set_rules('message', 'message', 'trim|required');
if($this->form_validation->run() == FALSE)
{
echo '<div class="error">'.validation_errors().'</div>';
}
else {
$mobile_number = $this->input->post('mobile_number');
$message = $this->input->post('message');
submitting the data to database.....
}
我的表格是
<form class="tg-form-signup" action="<?php echo (base_url('Common/smsapi'));?>" method="post">
<label>Mobile Number: </label><input type="text" name="mobile_number" /><br /><br><br>
<label>Message: </label><textarea name="message" cols="25" rows="10"></textarea><br /><br><br>
<input type="submit" name="upload" id="upload" value="Send"><br><br><br>
</form>
如果发生任何错误,我将在div jserror中获得结果。
我想在将成功数据发送到数据库
后禁用发送按钮答案 0 :(得分:0)
在ajax post call的成功处理程序中添加以下代码:
$('#upload').attr('disabled',true);
为了更好地控制,请使用以下功能:
$.ajax({
type: "POST",
data: $('form.tg-form-signup').serialize(),
url: "YOUR POST URL",
dataType: false,
success: function(data)
{
//HERE YOU GET FORM SUBMISSION SUCCESS
},
error: function(e)
{
//HERE YOU GET FORM SUBMISSION error
},
});