When working with a JSP and servlet, I encountered an issue. In the JSP, I make an ajax call to the servlet which in turn calls a REST API to fetch JSON data. Using
json.serialize(true);
, I format the JSON data in the servlet before sending it to the frontend.
To display the formatted JSON data as it is, I send it to the frontend using
pw.write(myformattedjsontext)
. However, despite my efforts, the data arrives unformatted on the frontend, leading to a loss of formatting. I tried implementing the following code:
var xhrDetailsArgs={
handleAs: "text",
sync: true,
load: function(data)
{
document.getElementById("DetailsGrid").innerHTML = data + "";
},
error: function(error)
{
alert("Error while loading details"+error);
}
}
I am still unable to get the desired formatted data. Any assistance in resolving this issue would be greatly appreciated!