Нет ответа от $ .post WordPress ajax - PullRequest
0 голосов
/ 02 апреля 2019

У меня есть форма, которую я пытаюсь отправить и получить данные через WordPress AJAX.

Я не получаю ошибок в консоли, но я также не получаю никаких записей в функции .post

Прямая ссылка (форма по цене): http://e390b6a4.ngrok.io//product/test-product-1/

Javascript:

function checkZipInstall(zipCode) {
console.log(zipCode);
    jQuery.post(rzcc_ajax_script.ajaxurl, zipCode
    ,
        function(response_from_rzcc_action_function){
            response = jQuery.parseJSON(response_from_rzcc_action_function);
            console.log(response);
            console.log(response.install_possible);
            if(response.install_possible === "true") {
                console.log('true');
            } else {
                console.log('false');
                //window.location.replace(response.redirect_url);
            }



        }
    );
}

jQuery('#vehicle-group').repeater({
    btnAddClass: 'r-btnAdd',
    btnRemoveClass: 'r-btnRemove',
    groupClass: 'r-group',
    minItems: 1,
    maxItems: 0,
    startingIndex: 0,
    showMinItemsOnLoad: true,
    reindexOnDelete: true,
    repeatMode: 'append',
    animation: 'fade',
    animationSpeed: 400,
    animationEasing: 'swing',
    clearValues: true
});

/* Prevent Add Button Refreshing */
jQuery( ".repeater-add-btn" ).click(function( e ) {
    e.preventDefault();
});

jQuery('#product_form').on('submit', function(e) {
    e.preventDefault();

    var formData3 = jQuery(this).serializeJSON();

    checkZipInstall(formData3);

});

Решено

Как подсказал @charlietfl, мне нужно было включить в запрос параметр action.Обновленная функция здесь:

function checkZipInstall(zipCode) {
    jQuery.post(rzcc_ajax_script.ajaxurl,
        {
            'action': 'the_ajax_hook',
            'zipCode': zipCode['zipCode']
        },
        function(response_from_rzcc_action_function){
            response = jQuery.parseJSON(response_from_rzcc_action_function);
            console.log(response);
            console.log(response.install_possible);
            if(response.install_possible === "true") {
                console.log('true');
            } else {
                console.log('false');
                //window.location.replace(response.redirect_url);
            }



        }
    );
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...