weixin_33692284 2016-10-27 20:24 采纳率: 0%
浏览 56

Ajax总是返回0

My AJAX post always returns 0 and I have no idea why PHP

add_action('wp_enqueue_scripts','enable_signup_scripts');
function enable_signup_scripts () {
   wp_enqueue_script('signup',get_template_directory_uri().'/signup/script.js' , array('jquery'));
   wp_localize_script('signup', 'daten', array('ajaxurl' =>  admin_url("admin-ajax.php", null)));
};
add_action('wp_ajax_createuser','createuser');
add_action('wp_ajax_nopriv_createuser','createuser');
function createuser () {echo 'hello';};

Script.js

$.post(
   daten.ajaxurl,
   {
      "action": "createuser",
   }, 
   function(data){
       alert(data)
   }
)

Does anyone know the issue?

  • 写回答

1条回答 默认 最新

  • weixin_33724570 2016-10-28 06:21
    关注

    I think you are missing the wp_die() function in your code, wp_die() is compulsory use like below code.

    function createuser () {
      echo 'hello';
      wp_die();
      };
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64