View Single Post
  #9 (permalink)  
Old 07-16-07, 07:38 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
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:
  1. alert("Saving data to the file");
The code would do EXACTLY the same thing if you did:
php Code:
  1. <?php
  2. function create_file()
  3. {
  4.  $a = fopen("test_data_write_.txt", "w");
  5.  fwrite($a, "Hello World.\r\n");
  6.  fclose($a);
  7.  echo "Saving data to the file";}
  8. ?>
  9. <?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.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote