0

I am using JQuery to call a PHP file and then I am using

document.getElementById(output).innerHTML=data; 

in the success function to output the text coming from the PHP file. This is all okay and the output is all fine. Part of the response from the PHP file is also some inline javascript (I am using a simple alert as an example). So the PHP writes:

echo "<script>";
echo "alert('Hello World!');";
echo "</script>";

This Javascript is not executed somehow. It is written to the DOM but not executed. Is it because there's no event that triggers the Javascript?

This is the HTML output:

<script>alert('Hello World!');</script>
Gabriel Glenn
  • 1,174
  • 1
  • 13
  • 30
tom_lehnert
  • 49
  • 1
  • 7
  • 2
    Your problem is regarding `innerHTML`, not PHP script... One of many relative questions: http://stackoverflow.com/questions/2592092/executing-script-elements-inserted-with-innerhtml And if you use jQuery, then use it... `$('#output').html(data);` – A. Wolff Sep 16 '16 at 09:15
  • Thank you so much! That immediately solved it! – tom_lehnert Sep 16 '16 at 09:30
  • Maybe @A.Wolff can post the instructions as an answer that can be accepted, or this should be marked as a duplicate. – René Jahn Sep 16 '16 at 10:41

0 Answers0