1

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!

1

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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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