【问题标题】:Path for ajax url in WordpressWordpress 中 ajax url 的路径
【发布时间】:2014-07-03 18:27:49
【问题描述】:

如何在 wordpress 中调用 ajax url。通过一个javascript文件

我使用的是http://example.com/site/wp-content/plugins/pluginname/upload.php..

这是可行的,但现在我改变了结构。

现在我想调用一个类中的函数

e.g
class A{


    function xyz(){
    include('upload.php');
    }
    }

现在,我不是通过 javascript 文件调用 upload.php,而是将其加载到类中的 xyz 函数中。

所以我想要一种从 javascript 文件中调用 xyz 函数的方法。

谢谢

【问题讨论】:

    标签: javascript jquery wordpress


    【解决方案1】:

    阅读此链接http://codex.wordpress.org/AJAX_in_Plugins。是否需要注册wordpress hook wp_ajax。

    添加到您的 php 代码中:

    add_action( 'wp_ajax_xyz', array($this, 'xyz') );
    

    在 JavaScript 中

    var data = {
        action: 'xyz'
    };
    // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    $.post(ajaxurl, data, function(response) {
        alert('Got this from the server: ' + response);
    });
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 2012-07-26
      • 2018-11-07
      • 1970-01-01
      • 2014-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多