Ajax : Why success displays 0?

前端 未结 10 1188
生来不讨喜
生来不讨喜 2021-01-01 19:02

I use ajax with jquery and when I tried to display the result in popup. Then alert always displays 0

success : function(results) { 
alert(result         


        
10条回答
  •  轮回少年
    2021-01-01 19:31

    In your PHP function, make sure you're using echo instead of return.

    This was happening for me in a WordPress theme.

    function doAjax() {
        $result = getPosts();
        echo json_encode($result, true);
        die();
    }
    

提交回复
热议问题