Hey friends, so what happened is I developed a rest API using Nodejs Express and Mysql, It is working fine on my local machine, I then hosted it on Cpanel, now I am trying to fetch data from it and render it on my react app. Well fetching the data part works like magic, its even rendering in my console, but when I map the data on my react app it is giving the error below, and just a blank white page. May you please assist .
If the data object is still in a nested object (aka JSON) format, then using .map() on it won't work, as .map() is not a function for Objects.
Try converting data to an array of objects then use .map().
You can grab all the values with Object.values and push into an array that you can map
Related
I'm trying to fetch data from API on Server Side using async fetch() but now in the method, I'm trying to join a set object, that I'm calling it in the template and it isn't working.
Always giving me an error that required function is not a function.
Any idea on how to fix that?
I figured out the problem. The thing was that I wasn't using the right way to join a set. I was using
setObj.join("; ")
and this was working fine on the client-side.
But I think because of the different render engine on the server-side. It wasn't resolving.
Solved it using
[...setObj].join("; ")
This was a JavaScript mistake rather than Nuxt.
I'm new to this thing. Correct me if I'm wrong somewhere.
If I use a json file stored in one of my GitHub repos as a mock backend, I know how to fetch and read all the data. Is it also possible to edit or post new data to this json file? Would an alternative mock backend like Mocky.io be a better solution (to achieve full CRUD)?
I think you could store the information inside csv files or somehting like that, you would be recreating a database engine as MongoDB & create your own reader to find the info, or you could store the users info using local Storage,
However this would make your app very limited.
Here's the link for the documentation of local storage
https://developer.mozilla.org/es/docs/Web/API/Window/localStorage
Well if you want to try out CRUD operations you can use free JSON APIs like http://jsonplaceholder.typicode.com/ or
https://mockfirst.com/
where you can create, read, update and delete data using various api end points. It is better to go this way first then you could move on to updating a JSON file.
(UPDATE)
You can use https://jsonbin.io/
Here you can place your own data and use it as an API.
I have a JSON file 'DealerList.json' and I can access it from my app by importing it using
import DealerList from './json/DealerList'
let tasks = DealerList;
The tasks here contain the JSON and I can easily access it.
Is there any way by which I can update the JSON back like if I update the values OR if I delete the values. I have also tried require("fs") but that too is throwing error.
The JSON file is present in a folder called json in the React App.
No, and this is a good thing. You do not want any web browser to be able to come along and rewrite files on your HTTP server.
Write a web service which will read and update the data based on HTTP requests (with appropriate authentication/authorization to stop undesirables from changing the data). Then interact with it via XMLHttpRequest / fetch / an abstraction library wrapping one of them (like axios).
(Or use localStorage if you want to store the data on a per-browser basis rather than shared between visitors).
I'm using Parse Server as a back end (the open source version). I have an Android application that saves an object to the server's DB. The object is simply a key-value pair. When the Android application creates an object, it creates it as JSON object.
Now I want to retrieve the same object from an Ionic 2 app. In Ionic, I use the JS Parse API to access the back end. When an object is created in the JS API, it's created as a plain text object.
As a result I'm getting: 101 Object not found
It seems like what I need to do is to translate Parse plain text object to Parse JSON object.
This is what I tried to do:
According to the JS Parse documentation one of the methods of Parse.Object is toJSON(). I tried to apply this method in different combinations to the Parse object before creating query, but I always get an error: this.parse.Object.extend(...).toJSON is not a function
I tried to apply standard JSON Api (i.e. JSON.stringify) to the Parse object. In this case I'm getting an error: ParseQuery must be constructed with a ParseObject or class name.
I did very extensive search on internet and found nothing helpful.
Would appreciate any ideas on the matter.
Figured it out. The problem was corrupted disk on the server side. Created new server and new DB and everything works fine now.
I have a JSON file which is dynamically and contain match info including an unique id. The JSON is divided into 3 arrays live, upcoming and recent. Since i'm quite new to Javascript i'm wondering what would be the best way to go in order to make this livescore script. I need it to be updating without refreshing browser? What is my options? Maybe someone has a snippet?
The JSON is automatically updates through another script which is connected to a cron job, so the script does not need to do anything regarding the JSON. Only retrieve and show the data.
I'm using dreamhost, which gives me access to shell, so websockets and so on is an option.
You'll need a jquery user to give you a snippit for this one, but in vanilla ecmascript 6, you use an XMLHttpRequest object to get the JSON from your server. This object can request data from the server asynchronously and is triggered by the client/browser so you can update the live match info when and as often as you like. You would just have to write a function to replace the data on the webpage with the new info when it is updated.