I want to put some html code to a JSONObject inside a Java servlet and send to the client using ajax, this is my html code that I want to put into a string variable called "resultado" (escaping html characters):
resultado += "<a href=\"javascript:void(0);\">" + stringValue + "</a>";
This is the way I put the html code into a JsonObject (inside my servlet) through the variable that is called "resultado":
response.setContentType("text/html; charset=windows-1252");
PrintWriter out = response.getWriter();
jsonGeneral.put("error", 0);
jsonGeneral.put("contenido", resultado);
out.print(jsonGeneral.toString());
out.close();
Then, the "error" attribute of $ajax() function shows me the next sentence (browser console):
SyntaxError: illegal character
<a href="\"javascript:void(0);\"">abc123...
This seems the html escaping is not the correct.
jsonGeneral is a JsonObject JSONObject jsonGeneral = new JSONObject();
and this is my code client:
$('#cargaDocumentoForm').ajaxForm({
dataType: 'json',
beforeSubmit: ShowRequest,
success: SubmitSuccesful,
error: function (xhr, status, error){
var err = eval("(" + xhr.responseText + ")");
console.log("err: " + err.Message);
}
`, however). – jcflorezr Feb 05 '14 at 20:11