I would like to make a series of comments, but the overall length would be too long for a comment, so I have to write an answer.
-
You should state what is working and what is failing, and tell us what you have tried to get it working. Looking at your code is too general.
-
In wordpress, the jQuery alias
$
generally does not work. However, if you have the Developer Tools console open, you should get an error message. I always usejQuery
instead of$
just to avoid stupid errors. -
You state you would like to hover over a category, but your trigger is on click.
$( "#alabama" ).click(function() {
If you are not getting any hover behavior, try clicking.
-
Your AJAX call looks all right, though the call back function seems to be putting the data in the wrong location. If you want the query to happen on a hover, shouldn’t the
output
go into a tooltip? -
The action in the AJAX call is to
fetch_posts
but your PHP function is calledimport_post
. These two functions need to be identical for AJAX to work. -
Your PHP function uses the
$_REQUEST[]
variable. Since you are sending the AJAX via POST, then you can use the$_POST[]
variable. It probably won’t break or fix anything to change, but to me it makes more sense (the code is more readable). -
When I develop an AJAX call, I set up the jQuery AJAX call, like you have. Then I create the PHP function that handles the AJAX call. First, I just echo the data I sent via AJAX. Once I know that works, then I write the SQL, echo that to make sure there are no syntax errors. At that point, I grab the data I want and send it back. The last step is to properly display the data in the AJAX callback function.
OK, there’s your AJAX tutorial. Hope it helps.