Hallo,
ich habe festgestellt, dass meine AJAX Funktion im Frontend nicht mehr ausgeführt sind.
Folgenden Code habe ich eingebaut,
Functions.php
add_action('wp_enqueue_scripts', 'enqueue_javascript');
function enqueue_javascript()
{
wp_register_script('ajax', get_stylesheet_directory_uri() . '/js/ajax.js?gt=1', array('jquery'), NULL, true);
wp_enqueue_script('ajax');
wp_localize_script('ajax-script', 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php')));
}
Ajax.js habe ich ich im js Verzeichnis angelegt. Wird auch korrekt eingebunden.
Inhalt ajax.js
jQuery( document ).ready(function($) {
//Bindet fillAutomarken an Gravity Forms
$(document).bind('gform_post_render', function(){
//Bei Änderung Automarken - Automodelle neu laden
$( "#gform_wrapper_10 #input_10_7" ).change(function() {
fillAutomarken($);
});
});
});
function fillAutomarken($) {
var data = {
'action': 'prefill_form_automodelle',
'modell' : $( "#gform_wrapper_10 #input_10_7" ).val()
};
console.log("cool");
$.post(ajax_object.ajax_url, data, function(response) {
var sel = $("#gform_wrapper_10 #input_10_23");
sel.empty();
if ( response != null ) {
if( response.length > 0 ){
for (var i=0; i<response.length; i++) {
if (i == 0) {
sel.append('<option value="" class="gf_placeholder">Auswählen</option>');
}
sel.append('<option value="' + response.text + '">' + response.value + '</option>');
}
}
else{
sel.append('<option value="" class="gf_placeholder">Auswählen</option>');
}
}
}, 'json');
}
Ich erhalte den Fehler, dass ajax_object.ajax_url not defined ist. Hat sonst problemlos funktioniert. Weiß jemand Rat?