admin管理员组文章数量:1415467
Unless I end Ajax processing function by exit()
or die()
, the Ajax function receives desired and correct output but following by 0
.
Any idea why is that happening?
Is that meant to be like that or it could be fixed?
add_action('wp_ajax_get_homepage', 'get_homepage');
add_action('wp_ajax_nopriv_get_homepage', 'get_homepage');
function get_homepage(){
echo "get_homepage ->";
exit();
}
I've read at AJAX in Plugins, but why is that necessary?
Unless I end Ajax processing function by exit()
or die()
, the Ajax function receives desired and correct output but following by 0
.
Any idea why is that happening?
Is that meant to be like that or it could be fixed?
add_action('wp_ajax_get_homepage', 'get_homepage');
add_action('wp_ajax_nopriv_get_homepage', 'get_homepage');
function get_homepage(){
echo "get_homepage ->";
exit();
}
I've read at AJAX in Plugins, but why is that necessary?
Share Improve this question edited Oct 6, 2013 at 2:12 Radek asked Oct 4, 2013 at 11:58 RadekRadek 5951 gold badge11 silver badges26 bronze badges 2- Does it (the addition of 0) happen even if you're logged out of wordpress? – murdaugh Commented Oct 4, 2013 at 12:06
- Yes, even if I am not logged into WordPress. – Radek Commented Oct 4, 2013 at 12:14
1 Answer
Reset to default 40The default response from admin-ajax.php
is,
die( '0' );
...by adding your own wp_die()
or exit()
or die()
after returning your desired content prevents the default response from admin-ajax.php
being returned as well.
It also generally means that your ajax call has succeeded.
Ultimately, to answer your question, it's meant to work this way. What you are doing by exiting after returning your content is the right thing to do.
本文标签: plugin developmentWhy does WordPress add 0 (zero) to an Ajax response
版权声明:本文标题:plugin development - Why does WordPress add 0 (zero) to an Ajax response? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745231622a2648848.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论