在Wordpress的ajax网址的路径

时间:2014-05-15 10:45:20

标签: javascript jquery wordpress-plugin wordpress

如何在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函数的方法。

由于

2 个答案:

答案 0 :(得分: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);
});

答案 1 :(得分:0)