Making an ajax request from a different domain

If you want to use Admin-Ajax to output the content, you should use echo instead. There is nothing to be viewed when you use return, so you’ll get a 0. This quotation from the codex explains further about the 0 response: If the Ajax request fails in wp-admin/admin-ajax.php, the response will be -1 or 0, … Read more

Fatal error: Uncaught Error: Call to undefined function get_option()

Instead of doing this, simply write your own function inside the verifyapi.php and then include it in your plugin’s main file, by using this: require_once(‘verifyapi.php’); This way, you have access to WordPress’s function inside your verifyapi.php file. Now, inside your verifyapi.php file, create an Ajax handler (however I would recommend using a REST endpoint) : … Read more

Ajax call returning 0

When defining an Ajax handler, you should consider defining both for logged in and non logged in users. You can do so by using: add_action(‘wp_ajax_my_handler’, ‘callback_function’); add_action(‘wp_ajax_nopriv_my_handler’, ‘callback_function’); Now, as for your question. We can turn this code into a REST endpoint, if you are interested, which is faster and easier to set up. Let’s … Read more

How can I display a PHP foreach loop’s answers by AJAX

Your code is selecting from the database where cor_estado.estado_id equals $Estado_id = $_POST[“selectVal”];, but in your JavaScript you’re not sending an ID as $_POST[“selectVal”], you’re literally sending the text string “selectVal”: data:{action:’my_action’, selectVal: ‘selectVal’}, Change that to this, to send the actual variable value: data:{action:’my_action’, selectVal: selectVal},