When filling in 2 fields input to take to take data from fields and send the data via ajax?

How to implement a jquery so that when filling the two fields come from the data input of the fields and transmitted on ajax
<input type="date" class="form-control" name="start_date" id="start_date">
<input type="date" class="form-control" name="end_date" id="end_date">

Here for example take the data from the fields
var get_start_date = $('#get_start_date');
var get_end_date = $('#get_end_date');

Transmission via ajax
$.ajax({
 type: "post",
 url: "getDate.php",
 data: {"get_start_date ": get_start_date, "get_end_date ": get_end_date },
 cache: false, 
 success: function(response){
$("#message").text(response).show().delay(1500).fadeOut(222800);
}
});

How to make a condition that if both fields are filled in then immediately take data from fields and send it via ajax if one field is filled in or both empty then do nothing.
June 5th 19 at 21:27
1 answer
June 5th 19 at 21:29
var get_start_date = $('#get_start_date').val();
var get_end_date = $('#get_end_date').val();
if(get_start_date.trim() && get_end_date.trim()) {
$.ajax({
 type: "post",
 url: "getDate.php",
 data: {"get_start_date ": get_start_date, "get_end_date ": get_end_date },
 cache: false, 
 success: function(response){
$("#message").text(response).show().delay(1500).fadeOut(222800);
}
});
}

Find more questions by tags jQuery