using jquery (json) to get ajax database entries in wordpress - PHP not working
Posted
by Matt Facer
on Stack Overflow
See other posts from Stack Overflow
or by Matt Facer
Published on 2010-06-14T22:00:36Z
Indexed on
2010/06/14
22:02 UTC
Read the original article
Hit count: 405
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...
$.getJSON("http://www.offbeatattractions.co.uk/wp-content/plugins/wp-geo-extended/ajax/change_location.php?action=listpoints", function(json) {
alert(json.Locations.length);
© Stack Overflow or respective owner