how to know if facebook share was successful?

i am following this documentation to implement faebook share using javascript sdk

https://developers.facebook.com/docs/sharing/reference/share-dialog/

here is the full code.

<body>


<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId            : '${grailsApplication.config.facebookAppId}',
            xfbml            : true,
            version          : 'v21.0'
        });


    };
</script>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js"></script>




<a href="#" onclick="myFacebookLogin()">Share me</a>





<script>
// Only works after `FB.init` is called
function myFacebookLogin() {

    $('#fooBar').hide();
    $('#noThanksSection').hide();
    $('#status').show();
    
    
    
    var lnk = $('input[name=referralLink]').val();
    


    FB.ui({
        method: 'share',
        href: lnk
        }, function(response){


            if(response  &&  !response.error_code){
                    $('#nextSection').show();
                    $('#noThanksSection').hide();
                    alert("Post was successful!");
                    $('#status').hide();
            }
            else{
                    alert('Error occured! Please try again!');
                $('#fooBar').show();
                $('#noThanksSection').show();
                $('#status').hide();

            }


        });



}
</script>

<body>

Clicking on the button will show the share popup window. After sharing the post, the javascript true block should execute in if(response && !response.error_code){ but the false block is executing. The response is empty.

How can we know if the facebook post was shared or the popup window was closed without sharing?

I appreciate any help! Thanks!