Ways to parse a json document in vue.js

As a novice in web development, I am currently working with vue-cli3.0 and a local server.

<template>
    <div>
    </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component({
  components: {
  },
})

export default class Test extends Vue 
{
  mounted(){
      this.readJson("./resources/doc.json")
  }

    readJson(filePath) {
        var request = new XMLHttpRequest();
        request.open("GET",filePath, false);
        console.log(request)
        // request.send(null)
        // var my_JSON_object = JSON.parse(request.responseText);
        // alert (my_JSON_object.result[0]);
    }
}
</script>

After logging the request, the output reveals that many of its properties are set to null.

XMLHttpRequest {onreadystatechange: null, readyState: 1, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …} onabort: null onerror: null onload: null onloadend: null onloadstart: null onprogress: null onreadystatechange: null ontimeout: null readyState: 1 response: "" responseText: "" responseType: "" responseURL: "" responseXML: null status: 0 statusText: "" timeout: 0 upload: XMLHttpRequestUpload {onloadstart: null, onprogress: null, onabort: null, onerror: null, onload: null, …} withCredentials: false proto: XMLHttpRequest

I am seeking assistance as I encounter difficulties in this process.

I am unable to include an import statement here, which is why I would like to avoid using it.


Your help and guidance are greatly appreciated.

<template>
    <div>
    </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component({
  components: {
  },
})

export default class Test extends Vue 
{
  mounted(){
      this.readJson(require("./resources/doc.json"))
  }

    readJson(filePath) {
        var request = new XMLHttpRequest();
        request.open("GET",filePath, false);
        console.log(request)
        request.send(null)
        var my_JSON_object = JSON.parse(request.responseText);
        alert (my_JSON_object.result[0]);
    }
}
</script>

I went ahead and made changes to my code accordingly.

However, upon checking the request object again, the issue persists.

An error message appeared:

vue.runtime.esm.js?2b0e:587 [Vue warn]: Error in mounted hook: "SyntaxError: Unexpected token < in JSON at position 0"


Interestingly, while exploring "filePath.ngldoc," I discovered some data! Could this data possibly be in the form of a JavaScript object?

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 steps can I take to troubleshoot issues when creating a React app?

While attempting to set up a react application using npx create-react-app projectreact, I encountered the following error message: PS C:\Users\ahnaa\OneDrive\Documents\Web Developent\Reaact JS> npx create-react-app project ...

Utilize JSON parsing with a reviver parameter to filter out specific object properties

In the process of developing a Node.js server, I am working on a particular service that requires accepting a stringified JSON object while also implementing field whitelisting. To achieve both of these objectives, I intend to utilize JSON.parse() with the ...

Revise my perspective on a modification in the backbone model

I am new to using Backbone and I am currently practicing by creating a blog using a JSON file that contains the necessary data. Everything seems to be working, although I know it might not be the best practice most of the time. However, there is one specif ...

What is the best way to initiate a dialogue (updating component state) using Vue Router?

I am looking to enhance page state management using vue router. For instance: / should navigate to the home page. /login will keep the user on the home page while triggering a dialog with the login form. /register will also trigger the dialog, but this t ...

Tabulator: Unable to download - Download type not found in database

Seeking assistance with downloading/exporting data to Excel using Tabulator (4.9) and Vue. Despite including SheetJS in my project as recommended by Tabulator's page, I am facing difficulties. The error XLSX is not defined occurs when I use: import & ...

waiting for udp response in node.js using express

Currently, I am diving into the world of node.js programming and have encountered a challenge. While working with express, I came across an issue. When a POST request is made, it triggers a radius authentication process over UDP using the dgram module. Ho ...

What is the best way to include dynamic query parameters in the src attribute of a <script> tag?

As I develop a basic asp.net application, I encountered a situation where I needed to include a script with a dynamic query parameter in my aspx page. For instance: <script src="../javascript/script.js?v=#var#" type="text/javascript"></script> ...

When using Node.js, you may encounter the error message: "TypeError: brevo.ApiClient is not a constructor

My goal is to set up an automatic email sending system that, upon receiving details like name and email, will send a confirmation email to the provided email address with the message "subscribed." I've been working on this task for about 7 hours strai ...

The Django webpack loader for vuejs+typescript encountered an error and refused to run the script from due to its incompatible MIME type of 'text/html'

I'm currently utilizing Django as the backend and Vue3 as the frontend for my application. While I didn't encounter any issues on the development server, I'm facing problems with page rendering in production. Despite closely following all th ...

Mapbox GL - Incorporate a non-scaling polygon feature during zoom operations

Is there a method to incorporate a polygon that maintains its size regardless of zooming? Currently, when adding a polygon circle shape with a 10-meter radius and zooming out, the polygon shrinks in size as expected. However, is it feasible to include a s ...

Rearrange the sequence of numbers using JQuery when an HTML element is deleted

I'm currently working on a simple functionality where I have 5 rows, each with its own number. So initially, the rows are numbered from 5 to 1. If I remove a value like 3, the sequence should adjust to 4, 2, 1, indicating that I now have only 4 rows ...

Confirm the drag-and-drop functionality for customers by utilizing the accept feature

Is it possible to customize my draggable & droppable module with these classes? stackDrop1 (Kitchen) stackDrop2 (Road) stackDrop3 (Completed) https://i.sstatic.net/vxFCx.jpg If the Customer George is in the Road class, the Kitchen class will not accept ...

How can I combine three dynamic dropdown menus into a single dynamic multi-level dropdown using PHP and Javascript?

Hello everyone, I've created a three-level dynamic dropdown menu that includes categories, subcategories, and questions. Each category has a corresponding subcategory, and each subcategory has corresponding questions. Below is the code for this functi ...

Tips for personalizing the webpack compilation process for transforming .vue files into .js files?

As a beginner in the realm of webpack plugins, I've grasped the idea behind the html-webpack-plugin, which empowers users to personalize the generation process of html files by webpack. In a similar vein, I am on the quest for a plugin tailored for . ...

Error: Unable to access the 'receiver_id' property because it is undefined

This function is designed to notify the user when they receive a request in my messaging app for educational purposes. However, I am encountering an issue with the firebase console showing the error: firebase functions. TypeError: Cannot read property &ap ...

The execution of JS code is being hindered by PHP codeigniter

Utilizing some pre-owned code in my current project The code snippet below is responsible for adding a product to the wishlist within the view <p class="p"><a<?php echo "onclick='addtowishlist($product->id)'"; ?>>Add To W ...

Incrementally add a new object to an existing array of objects

I have an array of objects below. When I do a console.log, this is what I see: [Object, Object, Object] 0:Object name: "Rick" Contact: "Yes" 1:Object name:"Anjie" Contact:"No" 2:Object name:"dillan" Contact:"Maybe" Now, I wa ...

React's useState function does not update the FileReader

I've been working on extracting values from an XML file using the code below. However, I'm encountering an issue where the console always outputs 'undefined'. Can anyone help me identify where I might be going wrong? This is my JavaSc ...

Steps to align div directly to the left of the button that was clicked

I have a div in my code that is hidden by default. I want to show this div exactly left whenever the user clicks on the show button. Since there are multiple show buttons on my page, I would like to display the div as described above. <div id="me ...

Extract particular elements from an array and transform them into a new array

Presented below is an array: [{ "title": "Apple iPhone 7 Plus 32 GB", "category": "phone", "brand": "apple", "condition": "Used", "price": 800, "id": 0, "description": "Apple" }, { "title": "Apple Ipad Air 32 GB", "category": "tablet", "brand ...