在没有回声的情况下在PHP内运行javascript

So I have a php file on my server which handles HTTP POST requests. When it receives a post request, it runs a javascript script.

Currently I have the script with echo'...'; But the problem is that with the script inside echo, it simply sends the raw code to the place where the HTTP post was generated from without actually running the script.

Is there a way I can run the script without echoing it back.

Thanks

<?php

define('VERIFY_TOKEN', 'abc');
$method = $_SERVER['REQUEST_METHOD'];

if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' && $_GET['hub_verify_token'] == VERIFY_TOKEN) {
echo $_GET['hub_challenge'];
} 

else if ($method == 'POST') {

echo '
<script type="text/javascript" src="parse-1.4.2.min.js"></script>
<script type="text/javascript">         

        Parse.initialize("ID1", "ID2");

        var TestObject = Parse.Object.extend("Test");
        var testObject = new TestObject();
        testObject.set("key", "post");
        testObject.save();
</script>';
}
?>

you can try like this

<?php else if ($method == 'POST') {?>
<script type="text/javascript" src="parse-1.4.2.min.js"></script>
<script type="text/javascript">         

        Parse.initialize("ID1", "ID2");

        var TestObject = Parse.Object.extend("Test");
        var testObject = new TestObject();
        testObject.set("key", "post");
        testObject.save();
</script>
<?php }
?>

else i don't think there is any other way

When your browser receives the response, it's expecting proper HTML (and two <script> tags are not proper HTML). Try wrapping your response in some minimal HTML:

echo '
<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="parse-1.4.2.min.js"></script>
    <script type="text/javascript">         

            Parse.initialize("ID1", "ID2");

            var TestObject = Parse.Object.extend("Test");
            var testObject = new TestObject();
            testObject.set("key", "post");
            testObject.save();
    </script>
</head>
<body>
</body>
</html>';
}

Turns out that I can't really do that since javascript needs browser. And since there is only php file I can't make it work with js so I switched to all php.