Open responseText on a new page

Asked

Viewed 103 times

1

Is there any way to open the responseText directly in a new window? I explain:

The code I use sends data to a PHP file that returns N messages. If I do the following alert(event.target.responseText); it returns me in Alert the return HTML, as below:

inserir a descrição da imagem aqui

There is how to open this normal HTML, even on the same page?

  • You are wearing bootstrap?

  • No, I’m doing "on the arm"

1 answer

0

The tag iframe allows you to insert one HTML document into another. Example:

        document.getElementById('meuFrame').srcdoc = 
        "<html> \
            <body> \
                <p>Segundo documento</p> \
            </body> \
        </html>";
<html>
    <body>
        <p>Primeiro Documento</p>
        <iframe id="meuFrame" frameborder="0"></iframe>
    </body>
</html>

the attribute srcdoc ( HTML5 ) defines the contents of the iframe directly, I believe it is your case.

Note: Be careful with the content of iframes, as they can run JS like any other page. If you don’t trust the content provided for your iframe, read about the attribute sandbox.

  • No iframe, no way? Because it was very disfigured, I needed to "rewrite" the entire current page, acting as if it were an execution by php, not by ajax. Got it?

  • @No, I don’t understand. If you want to directly use the content returned by PHP, why not build the page already on the server instead of returning HTML in an event and then interpret?

  • I’m doing the process via Ajax, and I need to interpret the feedback that PHP generates, which is what I’m not getting. Because the only way he returns is with responseText, which does not generate the alert as it generated when it did without Ajax...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.