Jquery 使用Ajax id#插入然后表单不验证
我在这里写了一个ajax jquery代码Jquery 使用Ajax id#插入然后表单不验证,jquery,ajax,Jquery,Ajax,我在这里写了一个ajax jquery代码 **ajax jquery code:** <script type="text/javascript"> $(document).ready(function(){ $("#insert").click(function(){ var OPRID=$("#OPRID").val(); var OPRDEFNDESC=$("
**ajax jquery code:**
<script type="text/javascript">
$(document).ready(function(){
$("#insert").click(function(){
var OPRID=$("#OPRID").val();
var OPRDEFNDESC=$("#OPRDEFNDESC").val();
$.post('opr_insert.php', {OPRID: OPRID, OPRDEFNDESC: OPRDEFNDESC},
function(data){
$("#message").html(data);
$("#message").hide();
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file
});
return false;
});
});
</script>
$(document).ready(function(){
$("#insert").click(function(){
var OPRID=$("#OPRID").val();
var OPRDEFNDESC=$("#OPRDEFNDESC").val();
$('#divAjaxLoaderGif').show(); // show the loading message.
**$.ajax({
url: "opr_insert.php",
type: "POST",
data: {OPRID: OPRID, OPRDEFNDESC: OPRDEFNDESC},
success : function(data){
$("#message").html(data);
$("#message").hide();
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file
$('#divAjaxLoaderGif').hide(); // hide the loading message
}
});**
return false;
});
});
</script>
**ajax jquery代码:**
$(文档).ready(函数(){
$(“#插入”)。单击(函数(){
var OPRID=$(“#OPRID”).val();
var OPRDEFNDESC=$(“#OPRDEFNDESC”).val();
$.post('opr_insert.php',{OPRID:OPRID,OPRDEFNDESC:OPRDEFNDESC},
功能(数据){
$(“#消息”).html(数据);
$(“#消息”).hide();
$(“#message”).fadeIn(1500);//淡入insert.php文件给出的数据
});
返回false;
});
});
这里我的html和Ajax代码都在下面。我的问题是,当我使用Ajax id#insert时,然后表单不通过输入进行验证。需要输入type=“text”我怎么可能同时使用Ajax插入和验证呢?在此提前感谢我的html代码
<input type="text" class="form-control required" name="OPRID" id="OPRID"
minlength="5" required/>
<input type="text" class="form-control required" name="OPRDEFNDESC" id="OPRDEFNDESC"
required>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<a id="insert"> <button type="Submit" name="submit" class="btn btn-primary">
Save changes</button>
</a>
$(document).ready(function(){
$("#insert").click(function(){
var OPRID=$("#OPRID").val();
var OPRDEFNDESC=$("#OPRDEFNDESC").val();
$('#divAjaxLoaderGif').show(); // show the loading message.
**$.ajax({
url: "opr_insert.php",
type: "POST",
data: {OPRID: OPRID, OPRDEFNDESC: OPRDEFNDESC},
success : function(data){
$("#message").html(data);
$("#message").hide();
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file
$('#divAjaxLoaderGif').hide(); // hide the loading message
}
});**
return false;
});
});
</script>
接近
保存更改
让我们试试这个,让我知道它是否有效。谢谢参见**代码。希望能有帮助
$(document).ready(function(){
$("#insert").click(function(){
var OPRID=$("#OPRID").val();
var OPRDEFNDESC=$("#OPRDEFNDESC").val();
$('#divAjaxLoaderGif').show(); // show the loading message.
**$.ajax({
url: "opr_insert.php",
type: "POST",
data: {OPRID: OPRID, OPRDEFNDESC: OPRDEFNDESC},
success : function(data){
$("#message").html(data);
$("#message").hide();
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file
$('#divAjaxLoaderGif').hide(); // hide the loading message
}
});**
return false;
});
});
</script>
$('divAjaxLoaderGif')
是包含Ajax-Loader.gif的div
$(document).ready(function(){
$("#insert").click(function(){
var OPRID=$("#OPRID").val();
var OPRDEFNDESC=$("#OPRDEFNDESC").val();
$('#divAjaxLoaderGif').show(); // show the loading message.
**$.ajax({
url: "opr_insert.php",
type: "POST",
data: {OPRID: OPRID, OPRDEFNDESC: OPRDEFNDESC},
success : function(data){
$("#message").html(data);
$("#message").hide();
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file
$('#divAjaxLoaderGif').hide(); // hide the loading message
}
});**
return false;
});
});
</script>
ajax jquery代码:
$(document).ready(function(){
$("#insert").click(function(){
var OPRID=$("#OPRID").val();
var OPRDEFNDESC=$("#OPRDEFNDESC").val();
$('#divAjaxLoaderGif').show(); // show the loading message.
**$.ajax({
url: "opr_insert.php",
type: "POST",
data: {OPRID: OPRID, OPRDEFNDESC: OPRDEFNDESC},
success : function(data){
$("#message").html(data);
$("#message").hide();
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file
$('#divAjaxLoaderGif').hide(); // hide the loading message
}
});**
return false;
});
});
</script>
$(文档).ready(函数(){
$(“#插入”)。单击(函数(){
var OPRID=$(“#OPRID”).val();
var OPRDEFNDESC=$(“#OPRDEFNDESC”).val();
$('#divAjaxLoaderGif').show();//显示加载消息。
**$.ajax({
url:“opr_insert.php”,
类型:“POST”,
数据:{OPRID:OPRID,OPRDEFNDESC:OPRDEFNDESC},
成功:功能(数据){
$(“#消息”).html(数据);
$(“#消息”).hide();
$(“#message”).fadeIn(1500);//淡入insert.php文件给出的数据
$('#divAjaxLoaderGif').hide();//隐藏加载消息
}
});**
返回false;
});
});
这取决于您使用的验证库。例如,可以使用JQuery验证。那么在这种情况下,您使用哪一个库呢?我想我没有使用任何类型的JQuery验证,只使用必需的字段验证。您能告诉我如何在我的ajax代码中使用验证吗?您能告诉我如何使用来显示“success&failed”消息吗