I'm new to client and server side scripts, and I was wondering, how come they can't interact?
The major difference Code Conquest stated here is that:
... is called a client side language is because it runs scripts on your computer after you’ve loaded a web page.
And
A server side or back-end language runs its scripts before the HTML is loaded, not after.
Even if the server side script (e.g. PHP) has already been executed, how come it can't be changed (with JavaScript) after the page has loaded?
I want to call PHP from JS. For example, is there a possible way to do this?
setInterval(<?php someFunction() ?>,10000);
Sorry if I'm misinterpreting something, and please point it out to me.
Well they can interact, but not like you are imagining it.
Think of client side JavaScript as the browser, and think of server side code, well as the server.
Then they would communicate by sending messages between each other, the most commonly used method for exchanging messages would be JSON.
To sum this up, client side code can communicate with the server be sending messages through GET
or POST
requests, or by using AJAX.
The server can respond to those messages, and it can also (this was added in HTML 5 standard) send events to the client using WebSockets.