Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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';
    }
    exit;
}

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
add comment

1 Answer 1

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();
if(response){
    //do stuff
}
share|improve this answer
    
Ahh thank you, makes sense! –  Vertaxe Dec 10 '11 at 10:22
add comment

Your Answer

 
discard

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.