Solved

Wordpress AJAX

Posted on 2014-07-21
6
243 Views
Last Modified: 2014-07-22
I am following the code here  in my wordpress template

http://www.benmarshall.me/wordpress-ajax-frontend-backend/

But the problem is in my_action_callback i am trying to get the post or page id as the return value but it isn't working.  Any ideas as to what i am missing.  

// The function that handles the AJAX request
function my_action_callback() {
  check_ajax_referer( 'my-special-string', 'security' );
  global $post;
 
  $whatever = intval( $_POST['whatever'] );
  echo $post->ID;
  die(); // this is required to return a proper result
}

Open in new window

0
Comment
Question by:stargateatlantis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40210186
What is the purpose of line 6?
0
 

Author Comment

by:stargateatlantis
ID: 40210203
it was in the tutorial link I just copied it from there
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40210235
But what is it supposed to do?  I would not encourage anyone to copy tutorials without understanding the moving parts.  It doesn't make sense to me out of context (and it might not make sense in context, either).  Does it have a purpose that you understand?  I ask because it seems to assign a value to a variable that is unused in the function.  When I see something like that, that does not seem to make any sense, it's a code smell and I call the whole piece of programming into question.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:stargateatlantis
ID: 40210404
its a Ajax call within wordpress.  I think we are loosing ground on the original question.  I am not sure if you are familiar with it's back end or what you can do.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40210444
I understand PHP fairly well and understand WP at a journeyman level.  The code snippet evinces a technically incompetent concept.  Maybe if you can step back from trying to use this example and give us the "big picture" of the application in non-technical language we can help.  But please don't install any script you do not understand -- that's a recipe for confusion at every level.

I won't ask why you chose this particular programming example.  What are you trying to make happen?
0
 
LVL 29

Accepted Solution

by:
chilternPC earned 500 total points
ID: 40210449
check out the wordpress forum  this is similar and may shed some light

http://wordpress.org/support/topic/ajax-function-not-returning-any-results
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to dynamically set the form action using jQuery.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question