You don’t need to specify datatype in your AJAX call. Also, WP handles AJAX a bit differently, primarily:
$('#filter_evenement').submit(function(){
jQuery.ajax({
url:ajaxurl,
type:"POST",
data : {action: "evenements_filter_function", val1: "value1", val2: "values2"},
success:function(data){console.log(data);
var dataArray = jQuery.parseJSON(data);//parse JSON
},
fail: function( jqXHR, textStatus, errorThrown ) {
}
});
});
data has to contain action
which specifies the WP AJAX handler function in the backend. You can also pass all values you need to send here (e.g val1, val2
) Your evenements_filter_function()
is not utilizing any data from AJAX call, it’s just sending a response. But to access the values you’d check $_POST['val1']
.