Extracting raw data from the dojo.xhrGet request

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!

Answer №1

To obtain a JSON object in your data variable, modify the handleAs attribute to "json". Once done, utilize the code snippet below:

JSON.stringify(data, null, " ");

This will provide you with a nicely formatted JSON string.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React - warning - Avoid using <Link> outside of a <Router> context

Warning: Invariant failed: It is not recommended to use <Link> outside of a <Router> Encountering this while attempting to write a test for a component where test("renders post list div ", () => { const posts = [ { created: ...

Display a message stating "No data available" using HighCharts Angular when the data series is empty

My Angular app utilizes Highchart for data visualization. One of the requirements is to display a message within the Highchart if the API returns an empty data set. I attempted a solution, but unfortunately, the message does not appear in the Highchart a ...

Verifying whether every value in the X array is present in the Y array or not

Currently, I am working with two arrays: const arrA = [1, 2, 3, 4, 5]; const arrB = [1, 2, 3, 4, 5, 6, 7, 8, 9]; My goal is to determine if all elements in array A exist in array B. Here are a few scenarios for better clarity: const arrA = [1, 2, 3, 4, ...

Exploring the functionality of LINQ for sorting and searching through IEnumerable collections

I am currently new to MVC and LINQ, and I am in the process of learning how to use AngularJs and MVC for a new project that has been assigned to me. To accelerate my learning, I have turned to an online video tutorial. The tutor in the video utilizes a cod ...

What causes all the accordion panels to toggle simultaneously in a ReactJs application?

When I click on the + button in my accordion, all the sections open at once. What could be causing this issue? Here is my code: const questions = [ { id:1, question: 'What is React?', answer: 'React is a JavaS ...

Battle between Comet and Ajax polling

I'm looking to develop a chat similar to Facebook's chat feature. Using Comet would require more memory to maintain the connection. There seems to be a latency issue when using Ajax polling if requests are sent every 3-4 seconds. Considering t ...

Troubleshooting: Success with AJAX call in Chrome, but issues in IE

Having issues retrieving JSON data from a URL that displays the last 3 numbers of a webpage. The AJAX call functions correctly in Google Chrome but fails in Internet Explorer. I tried disabling caching using cache: false as suggested, but the problem persi ...

Obtain array buffer from NodeJS to capture frames from a video file

My current goal is to extract frames from a video in node without relying on a video tag. I am utilizing openvg-canvas for this task, which allows me to print images and use the canvas API functionalities successfully. The challenge lies in the fact that ...

Tips for sending an email without using MAILTO in JavaScript or jQuery

Today is a great day for many, but unfortunately not for me. I've been struggling with this issue for over two weeks now and can't seem to find a solution anywhere on the internet. Stack Overflow always comes to my rescue when things get really t ...

How to parse an array in JSON using Swift 3 and iterate through it

Figuring out how to parse JSON data in Swift 3 has been more challenging than I anticipated, especially coming from a Javascript background. Received response from API: [ { "ID": 1881, "image": "myimageURL", }, { "ID": 6333, "image": "myi ...

Ways to generate data following the integration of Firebase Firestore in Vue.JS

How can I display the orders data retrieved from Firebase in my browser console? See the image link below for reference. This is the code snippet for fetching data from Firebase and displaying it in the console: orders(){ const db = firebase.firestor ...

A guide on implementing Google reCAPTCHA in a Nuxt.js website

Trying to implement the recaptcha-module from nuxt-community in my Nuxt project but struggling with verifying if the user has passed the check. The documentation and example provided are not clear enough for me (https://github.com/nuxt-community/recaptch ...

Set iframe or form to be in a fixed position

Having issues with my site where an iframe is contained within a div. When only one character is entered in the telephone box, validation fails and red warning text is displayed. Furthermore, after clicking in the email box and pressing tab twice, the fo ...

The specified type `Observable<Pet>&Observable<HttpResponse<Pet>>&Observable<HttpEvent<Pet>>` is not compatible with `Observable<HttpResponse<Pet>>`

I'm currently attempting to integrate the Angular code generated by openapi-generator with the JHipster CRUD views. While working on customizing them for the Pet entity, I encountered the following error: "Argument of type 'Observable & ...

Create your own unique Semantic UI themes using the Semantic UI theme builder, complete with support for Font Awesome classnames and the ability to preview them with the

My admiration for Semantic UI and Semantic UI React knows no bounds. Not only are they phenomenal libraries, but their documentation is truly a work of art. Yet, crafting and keeping up with themes for these components can be quite the challenge. The task ...

The Angular model finally refreshes its values after a console.log() is executed

UPDATE After further investigation, I discovered that the issue was not related to Angular itself, but rather a mistake in the update function within the node server controller. I have provided the fix below for reference, and decided to keep this questio ...

Are you interested in creating and testing a web service using JSON and C#?

Struggling with creating a JSON WCF web service that connects to MySQL DB on my Server. Feeling quite confused about the whole process! Here's the code I have so far: [ServiceContract] public interface IService1 { [OperationContra ...

I am having trouble retrieving the Post values that were sent using jQuery ajax

UPDATE: After removing 'index.php' with .htaccess, I encountered a newly discovered issue which I am now working on resolving. UPDATE: Issue resolved! Turns out the problem was in the Javascript code: url: "/login/". It needed a trailing slash t ...

The issue of AngularJS $http.get not functioning properly with a jsp page has arisen due to its simplicity

1 / I developed a myPage.jsp page within an eclipse project named erixx : <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE> <html><head></head> <body> <% String aa ...

Retrieving data from a WebAPI in JSON format and then storing it in a Store

As I dive into learning ExtJS-4.2, I have been diligently following their MVC tutorial... I successfully constructed my controller, view, model, and store with hardcoded data. Additionally, I have set up a WebAPI for testing purposes which provides result ...