您好我创建表单并使用ajax发送数据,但是当textbox为空时,所需的html 5无法运行。
我想在点击提交/调用ajax之前,需要运行html 5。 我如何修复我的代码?
html5是否可以与ajax一起运行?
这是我的代码
<form class='form-horizontal' action="" role='form' method="post" id="f1" name="f1" >
<div class="form-body">
<input class='form-control' type=text name="category_code" required> <br/>
<input class='form-control' type=text name="category_name" required> <br/>
<textarea name="category_description" class='form-control' ></textarea> <br/>
<button type="button" class="btn default" onclick="location.href='<?php echo base_url()?>category'">Back</button>
<button type="reset" class="btn red" >Reset</button>
<button onclick="do_act('f1','category/do_add','category','Add Category','Are You Sure ?','info');" type="button" class="btn blue" >Submit</button>
</div>
</form>
<script>
function do_act(form_id,act_controller,after_controller,header_text,content_text,type_icon){
swal({
title: header_text,
text: content_text,
type: type_icon, // warning,info,success,error
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true,
},function(){
$.ajax({
url: '<?php echo base_url() ?>'+act_controller,
type: 'POST',
data: new FormData($('#'+form_id)[0]), // Form ID
processData: false,
contentType: false,
success: function(data) {
if(data=="OK")
{
swal({
title: 'Success',
type: 'success',
showCancelButton: false,
closeOnConfirm: true,
showLoaderOnConfirm: false,
},function(){
$('#'+form_id)[0].reset(); // Form ID
if(after!=''){ window.location = '<?php echo base_url() ?>'+after_controller; }
});
}
else if(data=="NOT_LOGIN")
{
swal({
title: 'Error',
text: "You Must Login Again",
type: 'error',
showCancelButton: false,
closeOnConfirm: false,
showLoaderOnConfirm: false,
},function(){ window.location = '<?php echo base_url() ?>'; });
}
else
{
swal({
title: 'Error',
text: data,
type: 'error',
showCancelButton: false,
closeOnConfirm: false,
showLoaderOnConfirm: false,
});
}
}
});
});
}
</script>
帮我谢谢