Writing to a JSON file and uploading to a server - javascript

I am pulling a JSON file from a server within my app. When my app deals with this data, I need to write some changes to this JSON file and upload back to the original source.
So if I wanted to edit and write the data in Category in the data below to "Full Stack", how could this be done? I then need to upload to the server to update at their end.
https://gist.githubusercontent.com/planetoftheweb/4069235/raw/0ca9457d10f9ff0be578a699954910d7d6626726/sampledata.json

Related

how to send data on file with sendFile in express

I am trying to parse my csv file in server and return back the information after parsing and analyzing the data in csv.
I am not that used to express and i dont know any view engine.
I plan to use
res.sendFile(path.join(__dirname, "/index.html"));
to host my index file.
What are the other way than ajax and view template that can I send data to the index.html with sendFile.
I am sending JSON files from server to client
Any kind of help is appreciated !!!
When a client (such as a browser) makes a request you can respond with one thing.
You can respond with:
The contents of a file as you are now (although you should use the static middleware instead of rolling your own end point handlers (without caching) one-by-one)
A template + some data rendered into a single file (using the view engines you haven't gotten around to learning yet)
Some JSON (typically in response to an Ajax request so the a JS program running in an HTML document get add more data to the existing HTML page)
Something else
If sending an unmodified file is not what you want, then don't use sendFile.

Send JSON blob as a file

Is it possible to send JSON to an endpoint which expects a file using Nodejs? This Auth0 endpoint expects a file containing JSON:
https://auth0.com/docs/api/management/v2#!/Jobs/post_users_imports
But really I don't want to have to save a file as I'll be making this call quite often. Ideally I'd like to be able to construct the JSON programmatically and then hit this endpoint with that JSON rather than a file - but still have the endpoint see that content as a file.
Is this possible?

Request php generated json data via javascript and meanwhile log in php

Currently I have a working javascript/jquery file that makes a request to a php file to retrieve json data. This works great.
Some information is taken from the server and send back to the javascript/jquery.
So:
Request from js to exchange.php ==>
exchange.php access database and gets certain data
<=== response from exchange.php to jquery to send data to js
js uses data to make some changes to the website (changes phonenumber)
This has to be done as fast as possible. But after I have send the data to the js I want the same exchange.php log this data + some userdata to another database. For speed reasons I want to do this after the data is sent to the javascript. Is this possible?
Currently I just call the logging class after I echo'd json_encode(); But does it make a difference? Or will the json be send only after the whole php file has finished running?

xhrpost to download on the fly generated excel file on the server

I have the below requirement.
I have a data grid, which has huge amount of data. I have a download button, when clicked data grid data has to be downloaded to an excel. This data grid data I want to send to server through a rest call using xhrpost. With this data i will construct an excel file on the fly on server side and i will return the response to the client. My client by seeing this response should open popup for downloading the response to save as the file.
I am seeing the following problems here :
the data is huge. so , I can't use window.open way for sending the data in GET format.
I don't have an URL on server which will access file, as i am generating file on the fly and sending response to client.
How will i achieve my use case to download file using xhrpost on the fly, not storing the file anywhere?
Please reply as I am breaking my head how to do this? It will be of great help.
Thanks,
Sreenivas

Download CSV from ajax post request

I'm posting json to my server and I want to return a csv response and have my browser automatically download the csv.
I know there have been some questions on SO exactly about this topic on the past. So far, I've gathered the following solutions:
Put the request into <form> element. This isn't possible because the JSON is nested and too large to be posted as a string.
Save the csv file (get request) onto the server and then have a separate post request to download it. This is not ideal because I don't want to keep a bunch of useless csv files on my server.
Is there a better solution? Can I make a Post request act like a form submission and automatically get the file to start downloading?

Categories

Resources