Wednesday 7 September 2016

Wordpress and AJAX headaches for days

I just spent over 3 hours wondering why my ajax function only returns 0, yet when I use the exact same function in PHP elsewhere, it returns the correct value.

Turns out, all ajax functions must exit, otherwise the wordpress engine will take over and do other evil things, ending up in world domination and the destruction of mankind!

So remember, echo and exit, or your life will be hell!



add_action( 'wp_ajax_my_function', 'my_function' );

function my_function() {
    echo 'response';
    exit;
}

No comments:

Post a Comment

Devlog 8: AI and Radar explanation.