1

I am creating an app that uploads an .xls file to a server, and the response is a text/html response. I would like to preview the response (exactly as in the developer tool). Something like:

        axios.post(config.serverUrl + "/file", formData)
            .then(response => {

                //Preview response code
            }

I tried dangerouslySetInnerHTML={{ __html: {response.data} }} but that did not work.

Response example:

<!DOCTYPE html><html><head><style>table, td{    border: 1px solid black;
    border-collapse: collapse;
    padding: 9px;
}</style><title>file3500064108648651012.tmp</title></head><body><table>
<tr><td>Sheet 1</td></tr>
<tr><td>Test</td><td>Test1</td><td>Test2</td></tr>
<tr><td>test</td><td>test1</td><td>test2</td></tr>
</table></body></html>

The preview should then look like:

<!DOCTYPE html><html><head><style>table, td{    border: 1px solid black;
    border-collapse: collapse;
    padding: 9px;
}</style><title>file3500064108648651012.tmp</title></head><body><table>
<tr><td>Sheet 1</td></tr>
<tr><td>Test</td><td>Test1</td><td>Test2</td></tr>
<tr><td>test</td><td>test1</td><td>test2</td></tr>
</table></body></html>

1
  • Can you provide a short example of the response, and also your desired behaviour? Commented Nov 13, 2020 at 12:36

1 Answer 1

3

You can use dangerouslySetInnerHTML to set HTML directly:

 <div dangerouslySetInnerHTML={response} />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.