No, you don't get the point.
JavaScript doesn't call the create_file() function.
It is called on the server
BEFORE the page is sent to the client.
The SERVER replaces the function call with the text "Saving data to the file".
The browser and JavaScript interpreter can only see this:
JavaScript Code:
alert("Saving data to the file");
The code would do EXACTLY the same thing if you did:
php Code:
<?php
function create_file()
{
$a =
fopen("test_data_write_.txt",
"w");
fwrite($a,
"Hello World.\r\n");
echo "Saving data to the file";
} ?>
<?PHP create_file() ?> <!-- This function call is executed and replaced by the returned text as soon as the server encounters it. -->
No JavaScript can ever call PHP code on the server, because the browser doesn't know the PHP code exists, nor could it ever get access to it.
If you don't believe me, try removing all JavaScript code in that example and it will still work.