如何在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函数的方法。
谢谢
发布于 2014-05-15 18:50:44
请阅读此链接http://codex.wordpress.org/AJAX_in_Plugins。你需要注册wordpress钩子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);
});发布于 2014-05-15 19:00:30
https://stackoverflow.com/questions/23676012
复制相似问题