WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I've set up AJAX with Wordpress properly, having followed some good tutorials, and it's working great. One thing I can't quite work out is how to properly return either TRUE or FALSE from within the callback function.

My php function is as follows:

function my_callback() {
    if(something()) {
        echo 'false';
    } else {
        echo 'true';

In the JS do I simply do if(response == 'true') { // do something } or is there a better way? This might seem a little trivial but this is the first time I'm really using AJAX!

share|improve this question
up vote 1 down vote accepted

this would work to:

function my_callback() {
    if(something()) {
        echo 1;
    exit; //no text sent or even exit('0'); will work

and in js:

var response = do_ajax();
    //do stuff
share|improve this answer
Ahh thank you, makes sense! – Vertaxe Dec 10 '11 at 10:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.