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?

图片转代码服务由CSDN问答提供 功能建议

我发现这是插件来创建插件。

我遇到了问题,如何拨打ajax电话? 作为文档,我创建了 plugin-name / includes / class-admin-ajax.php 并将我的 wp_ajax _ 挂钩放在那里,但好像挂钩无法识别 然而。

class-admin-ajax.php

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

javascript section

 &lt; script&gt; 
 jQuery(document).ready(function($  ){
 $('#submit')。click(function(){
 var url = ajaxurl +“?action = test”; 
 $ .get(url,function(){
 
})  ; 
})
})
&lt; / script&gt; 
   
 
 

ajax调用始终返回0.看起来像 wp_ajax_test 尚未注册。 你能指出我的错误在哪里吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题