$.ajax function() not working
Ive made a form validation with jquery with the following code
$('#save').click(function(){
$.ajax({
url: "../scripts/availability.php",
type: "POST",
cache: false,
data:{
stamp: $("#stamp").val(),
jprefix: $("#jprefix").val(),
tprefix: $("#tprefix").va开发者_如何学JAVAl(),
starting_date: $("#starting_date").val(),
ending_date: $("#ending_date").val(),
starting: $("#starting").val(),
ending: $("#ending").val(),
colab_id: $("#colab_id").val(),
id: $("#id").val(),
session_id: $("#session_id").val()
},
dataType: "html",
success: function(msg){
if($(msg).html()==1){
if($("#starting").val() < $("#ending").val() && valDate()){
$("#serviceForm").submit();
}else{
alert ("Conflicto na data ou hora do serviço");
}
}else{
alert("Sobreposição de Colaborador");
}
}
});
});
function valDate(){
if($("#starting_date").length){
if($("#starting_date").val() <= $("#ending_date").val()){
return true;
}else{
return false;
}
}else{
return true;
}
}
some times the form gets submited without the proper validation
Assuming your click event handler on #save is the form submit button, it looks like the form will submit normally (not via Ajax) since this is the default behavior. You need an explicit "return false" on the click handler
i've already found out wht was wrong with the validations.... everything was working properly wit the exception of the conparisson of values... in the form they are with int values.... but wen the value is getted by the JS it some as string... resulting in strange comparissons... as for the ajax it self is just another part of the validation preventing to have overlaping scheduals
精彩评论