How to send canvas using ajax

0

I wanted to send a canvas that I have in one html to another using canvas, the ajax code is this:

function ajax(){
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            respuesta(this.responseText);  
        }
    };
    xhttp.open("GET", "Snake.html", true);
    xhttp.send(); 
}

function respuesta(respuesta){
    var contenido=document.createElement("div");
    contenido.innerHTML=respuesta;
    var quiero=contenido.getElementsByClassName("canvas");
    document.getElementById("principal").innerHTML=quiero[0];
}

the html from which the canvas is extracted is the following:

<html>
    <head>
    </head>
    <script src="Snake.js"></script>
    <body>
        <canvas id="canvas" class="canvas"></canvas>  

    </body>
</html>

This is what is sent: [object HTMLCanvasElement]

    
asked by parrado 19.09.2018 в 10:43
source

0 answers