I have a form created based on append()
of JavaScript as a result of the obtained in AJAX to receive and manipulate PHP Array converted to JSON. I also have a on
to capture the form when it makes submit()
, but there's the problem, the form is not captured, and the submit
is done normally, the preventDefault()
does not work.
jQuery(document).ready(function($) {
var array_vehiculos = new Array();
$.ajax({
type: 'POST',
url: 'data/load_veh.php',
cache: false,
success: function(data){
array_vehiculos = JSON.parse(data);
$.each(array_vehiculos,function(index,val){
$(".content.c-veh").append(
'<div class="sub-item">'+
'<form method="POST" id="veh">'+
'<input type="hidden" name="val-veh" value="'+val['matricula_veh']+'">'+
'<button type="submit" class="nothing">'+
'<img src="img/taxi/taxi.png" class="imgfit">'+
'</button>'+
'</form>'+
'</div>'
);
});
}
});
$("#veh").on('submit', function(event) {
event.preventDefult();
alert("Hola");
});
});
Edit
- I had an error in writing preventDefault (), I had written preventDefult ().