Ajax request with PHP does not recognize scripts

0

I am creating a code, where I send a form with ajax and return the result obtained in a PHP file (comment.php), however this file ignores the scripts linked in the page where the form is contained (question.php):

Ajax code (question.php):

    jQuery(document).ready(function(){
    jQuery('.formcomment').submit(function(){

    var dados = jQuery( this ).serialize();

       jQuery.ajax({
         type: "POST",
         url: "comment.php",
         data: dados,
         success: function(response){

          var editorContent = tinyMCE.get('camporesposta').getContent();
          if (editorContent == "" || editorContent == null){
           $("#aviso").html("<div class='alert alert-warning alert-dismissible' role='alert'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button><strong><i class='fa fa-meh-o'></i> Preencha o campo de resposta!</strong></div> ");
          } else{
            $("#aviso").html("<div class='alert alert-warning alert-dismissible' role='alert'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button><strong><i class='fa fa-meh-o'></i> Resposta inserida com sucesso!</strong></div> ");
             document.getElementById("ajaxrespostas").innerHTML=response;
            }



         }
        });
        return false;
      });
    });

In this file I linkei the scripts below:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><scripttype="text/javascript"  src="node_modules/bootstrap/js/tinymce/tinymce.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>
<script type="text/javascript" src="node_modules/bootstrap/js/tinymce/plugins/tiny_mce_wiris/tests/js/google_analytics.js"></script>

However, when returning the page (comment.php) in the variable "response" defined in the ajax code, it simply fails to recognize the above script:

comment.php:

<?php 
    require_once 'db.php';
    include 'functions.php';
?>

<?php

    // Variável enviada do formulário 
    $resposta= $_POST['resposta'];
    $idpergunta= $_POST['idPergunta'];

    if ($resposta == null){
        echo "falha";
        die();

    } else{


    $sql = "INSERT INTO respostas (texto, idUsuario, datapostagem, idPergunta) VALUES ('$resposta', '$iduser', current_date, '$idpergunta')";
    $insert = $mysqli->query($sql);

    include("comentarios.php");
}

result (page question.php, initially with scripts being recognized):

resultafterajaxrequest(pagequestion.phpwithcomment.phppagereturnedinresponsevariable,unrecognizedscripts)

As you can see, the scripts responsible for the text editor and mathematical formulas are not loaded.

    
asked by anonymous 28.10.2018 / 04:07

0 answers