Home > Mobile >  AJAX select2 in WordPress
AJAX select2 in WordPress

Time:12-22

I am trying to put AJAX results to enter image description here

I am getting error in console.

enter image description here

CodePudding user response:

You need action parameter in your ajax call :

let selectEle = cellEle.children("select").select2({
    ajax: {
        url: "/wp-admin/admin-ajax.php",
        data: {
            'action' : 'get_data',
        }
        dataType: 'json',
        processResults: function(data) {
            return {
            results: data
            };
        },
    }
});

The value of action in JS refers to "wp_ajax_get_data" and "wp_ajax_nopriv_get_data" action names.

  • Related