I have a form, My JS code is below the HTML Form.
If the url doesn't exist if want to show an alert (like the file exist) and prevent the validation of the submit (so refresh page) .
I may use return true or false ? If it's the case where have i to put them ?
echo '<form id="gestion_form" method="post" action="#" enctype="multipart/form-data">';
....
echo '<button class="btn btn-green" style="margin-left: 10px; margin-bottom: 15px;" type="submit" name="Envoyer" id="envoyer">MODIFIER !</button>';
echo '</form>';
<script type="text/javascript">
$(function() {
$("#envoyer").click(function() {
$("#loader").show();
var file = $("#vignette").val();
var address = window.location.protocol + '//' + window.location.hostname;
$.ajax({
url: address + "/admin/img/" + file,
success: function(data){
alert("the file exist");
// Return false here or true ?
},
error: function(data){
// Return false here or true ?
}
});
});
});
</script>