Extract information from non-JSON formatted response

Here is the fetch request that I am working with:

    fetch('https://cdnjs.cloudflare.com/ajax/libs/jsbeautify/1.7.5/beautify.js')
     .then(function (result) {
       console.log('here is our content:', result.body);
     })
     .catch(function (err) {
       console.error(err.message);
     });

...

From what I understand, result.body is a ReadableStream. Since the data is not in JSON format, using result.json() results in an error.

How can I go about reading the text from the response?

Answer №1

Indeed, this is the proper way to do it:

fetch('https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.5/beautify.js').then(function (response) {
  return response.text();
})
.then(function (data) {
  console.log('This is the fetched content:', data);
})
.catch(function (error) {
  console.error(error.message);
});

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

What is the best way to delete a property from an object in an array using Mongoose? This is crucial!

Doc - const array = [ { user: new ObjectId("627913922ae9a8cb7a368326"), name: 'Name1', balance: 0, _id: new ObjectId("627913a92ae9a8cb7a36832e") }, { user: new ObjectId("6278b20657cadb3b9a62a50e"), name: 'Name ...

Updating Kendo by modifying the Angular model

While working on a project with Angular, I recently discovered the Kendo-Angular project available at . I successfully integrated Angular-Kendo into my project and it seems to be functioning well, except for updating models in the way I am accustomed to. ...

How can I create a JavaScript loop that continuously prompts the user for input until they type "exit"?

Can you help with a JavaScript challenge? I am looking to create a loop that continuously asks the user for input until they type "exit". Once they do, I want the program to display the minimum value that was entered. var students = prompt("Enter Stude ...

Unable to retrieve the value of a textbox located within a gridview

In my grid view, I have a textbox nested inside a TemplateField. I want to retrieve the value of this textbox when a button is clicked: This is where I create the textbox: <ItemTemplate> <asp:TextBox runat="server" ID="txtEmail" Text=&a ...

Ensure that a JavaScript prompt appears when a form is selected in a dynamic HTML field

My PHP script generates a table form with results from a database query for users to edit records. The form can display up to 30 records. If the VoidTag checkbox is checked when the form is submitted, I want the user to confirm this action. If it is not ...

The post request for Ajax is having trouble accessing the post variable

codeigniter 2.0 form.tpl: <form class="form-book" id="class-form" method="POST"> inside full of checkbox.... <button type="button" class="btn" id="submit-btn">Submit</button> </form> <script> $(document).ready(function() { ...

Tips for integrating reCaptcha with AJAX using the .load() function

Looking to integrate reCaptcha with the jQuery '.load' ajax function for passing information to a PHP contact form. Managed to send name, subject, and other values using this method, but unsure about passing reCaptcha info. Encountering a PHP er ...

Using Rails with Ajax to display various partials on a webpage

I'm trying to implement a feature where I can submit a post via an Ajax call and have it disappear from the page without having to do a full reload. However, I'm struggling to connect all the pieces together. On my page, I have a list of pending ...

Updating React Native using setState is not possible

In my React Native application, there is a function that deletes an item: delete(index){ this.setState({deletedIndex:index, cachedCart:this.state.Cart, Cart: this.state.Cart.splice(index,1) }, function(){ console.log(th ...

Guide on transferring data from a JavaScript input to Flask

I have a table with buttons assigned to each row. Upon clicking a button, such as row 3, the ID corresponding to that row will be displayed in an alert message as well as logged in the console. My ultimate goal is to transmit this row ID to Flask Python so ...

Trouble with parseJSON when handling form POST in Python

I'm struggling with a javascript HTML page that has an action POST to a python file, expecting a JSON response back. Despite my efforts, I can't figure out how to catch and parse the JSON data. The HTML and python code excerpts below should show ...

Troubleshooting: Error in angular JavaScript due to minification: $injector:modulerr Module Error

After defining my angular code as shown below, I encountered an issue when trying to minify the javascript. The error message displayed was: $injector:modulerr Module Error. angular.module('myModule').controller('MyController', functio ...

Clicking on the LI element will automatically trigger a click event on the input radio button

Whenever I click on an li element, I want the corresponding radio input to be selected. However, when I try to do this, I'm seeing an error in the console log: Uncaught RangeError: Maximum call stack size exceeded How can I resolve this issue? Bel ...

Can an ongoing asynchronous call be canceled regardless of its current status?

As I enter text into my textfield widget, a request is sent to the server with every character typed in order to retrieve matching data. However, when I type rapidly, the server gets swamped with requests causing my control to freeze. To address this issu ...

Oops! There seems to be a problem with your AngularJS/JavaScript code. The error message is "Uncaught ReferenceError:

As I venture into the world of AngularJS and JavaScript, I am working on creating a 'blog' using these technologies. Here is my HTML view code- <div ng-controller="Controller1"> <form ng-submit="sub()" role="form"> Title: <textar ...

JavaScript - Issue arises when evaluating the sine of complex numbers of large magnitudes

I have developed a unique sine calculator that can handle the evaluation of the sine of complex numbers by utilizing polar coordinates and computing part of the infinite series defining the sine function. The calculator performs smoothly when dealing wit ...

Using JavaScript, you can manipulate the position of a line on a canvas to

I want to create a feature where users can manipulate lines on a canvas by skewing them. This means they would be able to drag one end point of the line to a desired point on the same x-axis using JavaScript and HTML5 canvas. Can someone please provide g ...

Passing Values from JQuery to PHP

I have been attempting to retrieve values using a button in jQuery and send them to PHP. Here's how I went about it: My HTML <button class="button" name="reject" value="<?php echo $row['mail']; ?>" type="submit">reject</butt ...

Having trouble leaving comments on a post in meteorjs

I'm encountering an issue where I can't seem to add comments to a specific post. The comments aren't being inserted into the mongo database. Comments = new Mongo.Collection('comments'); Template.comments.helpers({ 'commen ...

jQuery function used to create an HTML menu

My goal is to dynamically update the HTML file generated by a PHP script when I modify an item in a drop-down menu using jQuery. Here is the code: JQUERY <script type="text/javascript"> $(document).ready(function() { $('#regioni&ap ...