The problem here is one of not understanding where certain code is executed in the cycle of a web app, so let’s review. In a nutshell:
|Request Cycle||Where it happens||Primary language|
|HTML Response or JSON/XML||Network||HTTP|
When you need data to cross from one environment to the other, you have to do it through a HTTP request. That is the core of web application technology!