dongwupu5991 2017-03-19 05:46
浏览 101
已采纳

在插件wordpress中创建ajax调用

I found this plugin to create plugin.

I got an issue, how do I make an ajax call? As the docs, I've created plugin-name/includes/class-admin-ajax.php and placed my wp_ajax_ hook there, but seems like the hook is not recognized yet.

class-admin-ajax.php

<?php 
add_action('wp_ajax_test', 'test');
function test(){ die('yay'); }

javascript section

<script>
    jQuery(document).ready(function ($) {
        $('#submit').click(function () {
            var url = ajaxurl + "?action=test";
            $.get( url, function () {

            });
        })
    })
</script>

The ajax call always return 0. Seems like the wp_ajax_test is not registered yet. Can you point out where are my mistakes?

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 特别是3和4 帮帮忙
      • ¥15 C++完成两个子类的构建,基类已给出
      • ¥66 求拉格朗日插值某点的值
      • ¥15 简易的机票预定信息系统
      • ¥15 C++实现对称图形小程序
      • ¥15 大学生考试,各位大哥帮帮忙啊啊。有奖励
      • ¥15 运行和h2o时出现运行错误(无法分析 URI 查询,赋值后找不到象'train_h2o'
      • ¥15 机器学习算法做应用程序
      • ¥40 密码学大作业求大佬帮做
      • ¥15 C,C++,QT,做一个带界面小应用,有一定实用功能