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条回答 默认 最新

  • dtczp02204 2017-04-05 14:57
    关注

    [Update]

    So, I contacted the author, and he gave the answer after couple of days, here: https://github.com/joshcummingsdesign/wp-plugin-starter/issues/17

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于react-hook组件用函数控制是否渲染的及时性问题。
  • ¥50 Linux下的软件,要做模块化拆分。进程间通信是否有开源框架可以借用?
  • ¥100 修改原有的MYSQL存储代码,在最右边添加多列数据
  • ¥20 Open Interpreter 使用时报错: still has pending operation at deallocation, the process may crash
  • ¥15 qt中链接动态链接库,调用其中的函数,该函数的参数需要传入回调函数,自己创建的回调函数无法作为参数传递进去
  • ¥15 如何把api接口返回的json数据自动计算分页自动执行并写入mysql数据库。
  • ¥15 matlab svm二分类代码问题
  • ¥40 求一款能支持ios15以上的屏蔽越狱插件。比较好用的
  • ¥15 C++ QT对比内存字符(形式不定)
  • ¥30 C++第三方库libiconv 远程安装协助