How to set data into JSON file using js? - javascript

$.getJSON let us to get data from the file, is there any way to set data into the file? i have tried $.setJSON, but it shows me "$.setJSON is not a function".

You can't access the local file system using front-end Javascript. And there is no way on doing it.
What you can do is create a web server.
Send a request with the data in the server using AJAX
On the server, save the data by writing it on a file
That's pretty much it.

Related

Sending to JS data from Python and getting response back

so I am trying to send JS data, to be more specific, images responses Python file has collected, I need from python to send these images to JS and JS does a thing, (which I'll be coding) and sends the final result back to Python, how possible is that? I have 0 idea of doing that, looking forward for help, :cheers:
You can use API for the process. Post request & get request and so on. Also in Django you can deal with this process. Send variables from views.py and from template you can use them. There is similar question: Django Template Variables and Javascript

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?

How to get JSON / JSONP data using XAMPP local server?

I have set up a local server using XAMPP. Now I want to get JSON / JSONP data from that server.
Side question:
Do I need to somehow upload the JSON file on the server?
Or is there somePHPcoding for that? IF yes, which?
I have heard about some jQuery ajax call function, but it didnt work for me.
Any ideas?
You have several way of doing that. if the result is not dynamic you just create a json file on server and get it using URL.
if you want to do it dynamic in response to web page sent to server you can use the built in PHP function json_encode.
Please follow php documenation for json_encode
i don t think you need to do a lot of things.
json is a way to format data. you can do that returnin an output using json_encode()
exemples and info at http://www.php.net/manual/en/book.json.php
One method is to use json_encode() function available in PHP to send the data is JSON format to the client and handle the response in AJAX by mentioning dataType: json

Read/write json from js to file on server (not server app)

I'm working with a .js client and have and object that I need to write out to a file on the server. A couple of questions - file i/o with JavaScript is new to me... I was planning on using jquery and json. I'm using java serverside. I don't have a problem reading what I get back from my servlet, but the file i/o is killing me! A couple of questions:
I can open a file I generated myself via the .js with an $.ajax call, but it's not handling my json syntax (I tried both an $.getJson and $.ajax - handwritten json, so I might (probably) are doing something wrong with it). I used firebug's console and it looks ok...
How can I write my object to a file on the server?
Then, when I want to read it, what do I need to do to process it? Right now I'm using a jsonFilter function (uses JSON.parse if that's available, otherwise eval) to process data that I'm getting from the servlet.
The object I'm writing isn't simple, but it's not super complex either. There's an array that contains an array, but that shouldn't make a difference if the software is both reading/writing it.
Thanks for any help! I'm at a loss - tried alot of different things.
You can open a file located on the server via ajax by querying the file and loading it into a JSON object. You might want to LINT your JSON
You can not write to an object on the server via the client. This is a severe security breach.
Common practice is to change the JSON data and then send it via ajax to server-side code. The server will then do the file IO.
Yes using JSON.parse otherwise eval is indeed correct. I would recommend json2.js
The data should be fine as long as it passes JSONLint.
Your main issue is that it's impossible to write to the server from the client. Get the client to load the data through ajax change it and then query the server to update the file.
js don't have i/o property;
you should use ajax or http request to send message to server,and tell server to do de i/o action...

Categories

Resources