Passing sqlite data from Python to the view - javascript

I have an sqlite3 database I need to render in the front-end of my application on a GET request. Currently, I am able to render the data as a JSON dump as shown:
if self.path == "/stuff" :
self.send_response(200)
self.send_header("Content-type:", "application/json")
self.wfile.write("\n")
json.dump(db.getAll(), self.wfile)
I have now created a stuff.html where I want to present the data. For example, loop through printing the JSON data to the screen.
Instead of just dumping the data, how would I pass and call the JSON data from the database?

You can directly fetch data from the database using the following link:
access database using javascript from frontend

Related

How i can save json data into database and to foreach after save?

Hello developers I'm working on a categories tree list and want to save it into the database
I use this project from GitHub https://github.com/dbushell/Nestable
How I can save this data into the database?
[{"id":13},{"id":14},{"id":15,"children":[{"id":16},{"id":17},{"id":18}]}]
Front-End :
Through event listeners pass this data to the server as a query string.
Back-End :
Fetch the query string from server using POST method.
Convert the fetched data into the format acceptable to database (depends upon the framework and database used ).

How to request data from database in Laravel?

I've built a frontend in my vue3/laravel8 project and now want to get into the backend. I've been good at learning Vue3 but my knowledge base of Laravel is bare minimum.
I need to fetch an image link from a database and render it in a blade file.
In Vue3 I would use axios.get to send a request to a controller through an url and receive the image link. How do I send a request to my controller in Laravel? Is that even the right way to do it? I thought that maybe Laravel has some backend tricks up its sleeve, that Vue does not.
Edit:
I know that I can get data like this:
$data = DB::select('select * from db_name');
Does it have to be sent through an http response or can I just import the variable in the blade file?
Let's decompose your question to 2 sub-questions:
1- We need to fetch data when call axios request:
you have to update routes\api.php to link the coming request to the proper method located inside your controller
here's an example
2- We need to access our data in front-end:
Vue
If you using Vue components you can parse the response data then use it as you prefer
Laravel Blade System
You to call return view('your-blade-location', payload), payload => is your fetched data
here's a docs link

Tabulator save table to server

Tabulator get an option to parse table from remote server like ajaxURL:"https://mysite/data.json" and download table data as json.
But don't let to upload json data to same or another server.
How can I do the upload function to my table?
This is a very open ended question as that depends on which type of server you are using.
The standard method would be to make an AJAX request to the server, usually a POST or PUT request depending on whether you were creating or updating data.
You would retrieve the data from tabulator using the getData method, which return s an array of row data objects.
var data = table.getData()
You can then use an ajax library of your choice. Browsers come with the built in Fetch API or you could use a 3rd party library like Axios
How you send the data to the server is up to you as you will have to put the code in on the server to process it, so you will set the property names etc that the data will need to be set against in the request.

Node - Angular Passing POST data from Server to Angular client

I have a Node.js server with Angular on the client side. I'd like the following to happen.
User posts a large JSON to /postjson. The large JSON object is used in the controller to render some data visualization. I don't want to store the JSON in a database, it should disappear when the window closes. How do I pass this data to the controller?
A potential solution is to use a route /api/postjson and receive the JSON server side. But I don't want to store it. How do I then pass this object to the controller/service/provider whatever is required?

Laravel PHP - Custom JSON object from DB to PHP to JS to HTML

I have to create a custom json object (I need to decide what info goes where in what order) with data I get from PHP in my Controller.
As I see it, I think I need some roundtrips like this:
Get data from Laravel-form in my Controller (Input::get('name'))
Pass that data to JavaScript to build my JSON
Pass that JSON back to PHP
Convert this JSON to a string (to store it in Redis)
And when I try to read this data go the other way around:
Get data from DB
Pass data to JavaScript to get each element/node
Parse those values to html (to display the data from the json)
How would I pass variables from PHP to JS and back? Not sure how that works... A good explanation (with some code or example) would be much appreciated!!!
Or is there another 'better' way?
I am using Laravel 5.2 and NoSQL Redis. I need to create a somewhat complex JSON that looks like this and store that in Redis. This JSON will never be more than twice the size of this one shown here.
Thanks
to generate json data, you can do that with json_encode function in php. No need to pass to javascript to build json data.
http://php.net/manual/en/function.json-encode.php
update:
you can store the response of json_encode function in a variable and you can do whatever you want with that variable
$json_data=json_encode($data);

Categories

Resources