A
A
Alexander Sobolev2018-08-22 02:24:44
WordPress
Alexander Sobolev, 2018-08-22 02:24:44

How to pass get_option() value in ajax url correctly?

There is quite a standard ajax request for url, the value of which is taken (should be taken from the plugin option)
I suspect that the url variant: <? get_option('url'); ?> in the request will not work, and it gives back somehow with shit code ..
How to be? Is it really possible to do $get in php with the removal of a variable .. Or is there a more adequate option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan, 2018-08-22
@san_jorich

If I understand the question correctly, then this is done like this (copied from my code):

// download archive callback
add_action('wp_ajax_download', 'download_callback');
add_action('wp_ajax_nopriv_download', 'download_callback');
function download_callback() {
    global $wpdb;
    $data = $_POST;
    // здесь какие-то телодвижения
    print json_encode(array('key' => 'value'));
    exit;
}

well, in js:
$.post('/wp-admin/admin-ajax.php', data, function(response) {
  //что-то делаем
}, "json");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question