我卡在這裏:防止阿賈克斯與空白輸入提交,並選擇
//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();
,並沒有工作。在這種情況下,它會阻止空的投入,但是當我填的是輸入和點擊按鈕沒有任何反應..