我卡在这里:防止阿贾克斯与空白输入提交,并选择
//Saving Data
$('#saveButton').click(function(){
var teamA = $('#teamA').val();
var teamB = $('#teamB').val();
var date = $('#date').val();
var timeOfEvent = $('#timeOfEvent').val();
var live = "0";
if($("#live").is(':checked'))
live = $('#live').val();
$.ajax({
url : "ajax.php",
type : "POST",
async: false,
dataType: "json",
data :
{
'submitAddEvents' : 1,
'teamA' : teamA,
'teamB' : teamB,
'date' : date,
'timeOfEvent' : timeOfEvent,
'live' : live,
},
success:function(data)
{
if(!data.success) {
alert(data.message);
}else{
window.location = "addEvents.php";
}
}
});
});
这就是我已经有..这是“一切”确定的,但即使在inputs
required
和selects
当我点击按钮这将数据插入,而不防止空白输入或选择数据库...
什么,我已经做了 我把<form>
,我改变了我的AJAX
$('#saveButton').click(function(){
到
$('#saveButton').submit(function(ev){
ev.preventDefault();
,并没有工作。在这种情况下,它会阻止空的投入,但是当我填的是输入和点击按钮没有任何反应..