I'm writing a plugin for my wordpress site and am having trouble understanding the jquery ajax requests. In a nutshell, I am trying to get some user meta data loaded when the page loads.
我正在为我的wordpress网站编写一个插件,并且无法理解jquery ajax请求。简而言之,我试图在页面加载时加载一些用户元数据。
So in my javascript file I have a line:
所以在我的javascript文件中我有一行:
$.getJSON("http://mysite.co.uk/wp-content/plugins/myplugin/ajax/ajax.php?action=test", function(json) { // do stuff });
So the above DOES get called, but it's the PHP code I'm having trouble with. In the file ajax.php, I am making a database call, but NONE of the usual class information is available. I've tried including the admin ajax page, various other pages from my own plugin (which does work).... not sure what else to do!
所以上面的DOES被调用,但这是我遇到麻烦的PHP代码。在文件ajax.php中,我正在进行数据库调用,但是没有通常的类信息。我尝试过包含admin ajax页面,我自己的插件中的各种其他页面(确实可以工作)....不知道还能做什么!
The database call method works OK in my plugin code.. but I guess that the ajax.php file is outside the WP framework so that's why it's not working... but I don't know how to get it IN the framework!?
数据库调用方法在我的插件代码中运行正常..但我想ajax.php文件在WP框架之外,这就是为什么它不起作用......但我不知道如何在框架中获取它!?
I just need to use the $wpdb->get_results($sql);
command to get my SQL. The error returned from firebug is that I am making a call to an undefined function.
我只需要使用$ wpdb-> get_results($ sql);命令来获取我的SQL。从firebug返回的错误是我正在调用未定义的函数。
Thanks for any help...
谢谢你的帮助...
1 个解决方案
#1
1
Read this page, basically you only need to define a callback for an action and use the already defined Wordpress machinery.
阅读本页,基本上您只需要为动作定义回调并使用已定义的Wordpress机制。
#1
1
Read this page, basically you only need to define a callback for an action and use the already defined Wordpress machinery.
阅读本页,基本上您只需要为动作定义回调并使用已定义的Wordpress机制。