weixin_33722405 2013-05-01 21:10 采纳率: 0%
浏览 16

WordPress wp_ajax公开网址?

I would like to do an ajax request in my theme.

If I am login to the Back Office, the request does, but if I'm not logged in, the returns is null... What's the solution please ?

In my view :

$.ajax({
  type: "POST",
  url: 'http://www.mysite.com/wp-admin/admin-ajax.php',
  data: $('#EventForm').serialize()+'&action=event_form',
  success: function(response){
    if(response == 1){
      alert('ok');
    } else {
      alert('no ok');
  }
});

In the functions.php (works only if I am log in back Office)

add_action('wp_ajax_event_form', 'ajax_event_form');
function ajax_event_form(){
  global $wpdb; 
  ...
  echo true;
  die;
}
  • 写回答

3条回答 默认 最新

  • weixin_33724046 2013-05-01 21:17
    关注

    From the Codex: wp_ajax_nopriv_(action) executes for users that are not logged in. So, if you want it to fire on the front-end for both visitors and logged-in users, you can do this:

    add_action('wp_ajax_my_action', 'my_action_callback');
    add_action('wp_ajax_nopriv_my_action', 'my_action_callback');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器