I want to make it so that after sending a comment, their module will reload.
Using AJAX below, the contents of page2.php are inserted into the div I need .
function func() { var text = document.getElementById('input').value; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById('div').innerHTML = xmlhttp.responseText; } } xmlhttp.open("POST", "/page2.php", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); var request = "id=1"; xmlhttp.send(request); } When you call the func() function by pressing a button, it executes beautifully.
But when sending a message, a similar function is called, which, if sent successfully, inserts the following code into the div:
<script>func();</script> At the same time, the code appears on the page, but is not executed. Already tried to add to all sorts of wrappers listeners event, but the function is not executed. Tell me, what is the code in this case?
<script>func();</script>inserted? and why insert a tag script at all, and not just callfunc()again? - Grundy