How to have external PHP script echo to different parts of HTML page?

Viewed 33

I have an external PHP script that could echo an error, data, or different success messages from the same function call. These are echoed to a JS file which can display the data anywhere on an HTMl page. Is this the best way to do it?:

  1. Using "json_encode", create JSON with a status code key-value pair and a message/data key-value pair.'
  2. Echo back the JSON.
  3. Back in the JS file, retrieve the JSON and store it as a variable.
  4. Put it through an if or switch statement, where the I could use the status code value to determine where to d.gEBI() place the message value (or whatever I want to do with the data).

This is the only way I know that could work with this setup (an external php script called from either external JS file or inline JS in HTML page).

0 Answers
Related