How JS & PHP related with each other?

We found a PHP script is always having a JS code. A basic PHP applications must having JS interaction in script. On very basic level there are 4 types PHP & JS are relate with each other.

There are 4 scenarios;

  1. How to display PHP error message on page with bootstrap? We use this by simply storing PHP error message in variable & execute that PHP code in between Bootstrap body.
  2. How to display PHP error message in JS popup/alert?
  3. How to use JS data into the PHP block? For example some JS variable we need to store into PHP block to use further for server side process?
  4. How to use PHP data into JS block? May be this is the way why we use Ajax. Ajax is simply way to call a stand alone PHP file or block of PHP code by making a request of data -> Parse that data into JSON and come back to JS block and parse JSON into array. Now we have the PHP data in JS array format which we can use further. This is a async way to talk between frontend & backend server.

Explore more scenarios..