重定向到cron作业中的另一个页面

I have a page that I have to run twice a day on my server. I used the cron job in my cpanel. The page has an API call in javascript and the received data is saved to the database. Due to the reason that I have to run the javascript before the php script, the format is like following-

    <?php
    if(isset($_POST['get_data']))
    {
        //INSERT get_data to database
    }
    else
    {
?>
    <script>
        var api_data = //API call to get the data ;
        $.post("ths_page.php",
                {
                    get_data: api_data
                },
                function(data,status)
                {
                });
    </script>
<?php
    }
?>

If I run the page manually, the data gets saved. But I guess the cron job does not execute the post method. Is there any way to have it this way in a cron job? Any help is appreciated.

Cron jobs will only run pure

PHP CLI scripts

Whatever comes under PHP CLI cron jobs will only execute that part.

Your javascript will never execute on cron jobs. You need to find other solution for your requirement.