Everything happens on wordpress,

The request itself:

$(function(){ var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; $.ajax({ type: "POST", url: ajaxurl, data:{ action: 'weather_block' }, dataType: 'html', success: function(response){ $('.weather_block_page').html(response); console.log(response); }, error : function(jqXHR, textStatus, errorThrown) { $loader.html(jqXHR + " :: " + textStatus + " :: " + errorThrown); } }); }); 

And there is a file where the request comes in:

 function weather_block_ajax_request(){ echo 'test'; die(); } add_action('wp_ajax_weather_block', 'weather_block_ajax_request'); add_action('wp_ajax_nopriv_weather_block', 'weather_block_ajax_request'); 

In the console, I get 0, why?

  • make sure that the request comes to this file (at the beginning of the file insert exit('abc') - if in the abc console, then everything is correct). If everything is good here, deal with add_action . So your function does not hang on these hooks or these hooks do not work. Where did you find such hooks? is there a link? - Ivan Pshenitsyn
  • I see abc in source! Hooks took off. wordpress pages. I tried to change the name of the function and the action, the result is the same, 0 - Alexander Reizan
  • specify what is 0 and where you see it. You can take a screenshot for clarity. - Ivan Pshenitsyn
  • there’s nothing really to think about, in fact: if you put exit('abc') next to the code you give in php and you have abc output to the console - everything is fine with the request. Hooks do not work. Try others. - Ivan Pshenitsyn
  • codex.wordpress.org/AJAX_in_Plugins Well, in the console I see 0)) where else. - Alexander Reizan

0