views:

89

answers:

1

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.

So in my javascript file I have a line:

$.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!

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!?

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.

Thanks for any help...

+1  A: 

Read this page, basically you only need to define a callback for an action and use the already defined Wordpress machinery.

iBobo
thanks - I have read that page before, but never ACTUALLY REALLY read it.... Just spent some time and now I understand. I've hooked in to the admin as it suggested which is possibly working... just trying to establish a good json connection first, then will test the $wpdb class ... which I am sure will be ok to use. Many thanks.
Matt Facer