Unable to use php tags to declare variable from php to javascript

My approach looks like this:

It runs fine on my local Apache server but In here, It is showing an error telling “Invalid or Unexpected Token”. So, How do I fix this?

Javascript error or PHP error?

@mukeshAryal Can you be more specific, if possible with screeshots?? :slight_smile:

1 Like

JavaScript One! It seems so!

Javascripr line 43 is not recognising a variable.

Your PHP error has corrupted the JSON parsing on the JavaScript side. There are several things to fix:

  • Turn off error reporting in PHP outside of development environments, it’s not considered safe (if you are developing now, then do this last, as these errors are helpful for now)
  • Make sure that an undefined variable error can never happen, in any circumstances, in your PHP code, even under error conditions
  • Ensure that your JavaScript can gracefully handle an invalid JSON payload
1 Like

and what about the variable declaration? I can’t do that anyway?

Let’s check what your script is echoing.
Please add to your JS, after where you get the json from php, this
alert(var);
Replace var, with the json variable.