Use text()
instead of html()
:
$("div#output1").text(JSON.stringify(response));
This will create a proper text type node in the DOM and not escape to HTML.
If the problem persists, it may be server-side. In that case look at the HTTP response to see what you actually get from the server.
On chrome, press F12 to open the dev tools, go to network, reload the page with F5 and fire the AJAX request again. At that point you'll see the HTTP request/response entry. Click it, and inspect the response sheet, there you'll see the raw ASCII data served by the server. If that's still escaped then the problem is server-side.
In PHP use var_dump()
to output that string directly onto the page (without AJAX) and look at it. It may be already escaped in the database. In that case you'll have to unescape it somewhere along the response pipeline. The easiest thing will be to unescape it directly in JS on the client-side. That won't require you to change the rest of the application (namely, the input forms). Keeping escaped strings in the database is a good idea, in fact.
You may want to have <pre>
tags for the output of the text node:
<pre id="output1"></pre>