Php 在ajax成功后禁用
我的ajax脚本是Php 在ajax成功后禁用,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,我的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){
<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>
$(文档).ready(函数(){
$('form.tg form signup')。在('submit',函数(form){
form.preventDefault();
$.post('Comeon/sm',$('form.tg form signup').serialize(),函数(数据){
$('div.jsError').html(数据);
});
});
});
我的控制器是
$this->load->library('form_validation');
$this->form_validation->set_rules('mobile_number','mobile_number','trim | required |精确长度[10]| numeric');
$this->form_validation->set_规则('message'、'message'、'trim | required');
如果($this->form\u validation->run()==FALSE)
{
回显“”。验证_错误();
}
否则{
$mobile_number=$this->input->post('mobile_number');
$message=$this->input->post('message');
正在将数据提交到数据库。。。。。
}
我的表格是
<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>
在ajax post调用的成功处理程序中添加以下代码:
$('#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
},
});
使用jquery RemoveAttryYou可以通过JS禁用按钮,但需要在服务器上进行检查。为用户再次启用按钮是很简单的。
$.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
},
});