How to get value from WP database based on option value selected by onchange using AJAX – PHP?

I need your help with some code in my plugin, can you help me please? I need to create a select, when changing the selection, find the information about the selected item, I tried different ways but didn’t get success 🙁 How can you help me? This is my code:


ticker symbol selector’; foreach ($lista_company as $value) { echo ‘id_company.'”>’.$value->ticker.”; } echo “”; } ?>


jquery(function($) { $(document).ajax({ type: ‘POST’, url: ‘/wp-admin/admin-ajax.php’, // if using in plugin data ajax_params.ajax_url use: ‘json’, data: { action: ‘yourFunction’, newValue : newValue}, success: function(response) { console.log(response); }, error: function(errorThrown) { console.

But I don’t know how objetc. For returning

add_action(‘wp_ajax_yourFunction’, ‘yourFunction’); do your function() { $newValue = $_POST[‘newValue’], // query whatever you want with $newValue}

I took your example to implement in my code.

Leave a Comment