I have a javascript array of multiple files like
filelist=[{'name':file1name,file:file1},{'name':file2name,file:file2}]
I need to send this file to backend views.py using $http request.
How do i send this in angularjs?
Please modify this link plunker
Related
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
Since I am new to laravel api, I don't know hot to connect laravel api to html endpoint. My laravel api is working well and html web pages also completely finish. I just want to connect them together... Please explain how to connect these two.
Thank you
I would suggest two ways to go about this but it all depends on what your API does. If you are looking to serve the HTML with Laravel and have some parts of the application loaded by Laravels view() method, you'd basically need to break your HTML into blade files in resources/view folder and call the blade files via view() in controller to load the desired page.
However if you are looking for a separation of view and API where API is called by the view only for some information, you'd need to utilize AJAX via JavaScript to make a call to the API endpoint and retrieve the data (JSON) for use in your HTML site.
I use axios a lot and here is a sample call:
axios.get(url).then(response => { // do whatever here with the response data });
I'm not sure I understand you. But it reads like you developed your Laravel Application (PHP) and HTML separately. Laravel uses Blade (see: https://laravel.com/docs/7.x/blade) as a template engine into which you can inject PHP objects. Basically, the call of a web page (more or less) works like this:
The user is calling the url
URL goes to the routes/web.php
in this file you can call e.g. a controller
the controller called via (e.g.)
return view('my.site.nice-site', [ key => value]);
blade starts and displays the page to the user with the given key as variable.
I hope this helps you a bit. Otherwise I recommend, just to get started, the documentation from Laravel or YouTube.
I have created a couple of projects with Django.
Every time I try to send an ajax POST request from frontend to django, I have to use JSON.stringify() function, pass it inside the body of POST request and parse the JSON manually inside Django (using ujson, because of its faster).
My question is that why do I need to do this manually?
I searched a lot but unable to find the solution for this.
In angular 1.x, I used to include js in php pages and load the pages from server side code like CodeIgniter controller.
In angular 2.x, I unable to figure out that how I use server side features like $_SESSION?
e.g. I want to insert the data to mysql table and I will send data using POST service of Angular 2. How can I achieve that which user is logged in and created that record??
$city = $this->input->post("city");
$specialty= $this->input->post("specialty");
$data = array("city"=>, "specialty"=>$specialty, "createdBy"=>$this->session->userdata("userid"));
$this->db->insert("citywise", $data);
How to get this $this->session->userdata("userid"); because application is loading at client and everything is handling like REST services.
Using localStorage I can get login data on client browser but what about server?
Use JWT(Json Web Token) for the same purpose
refer this link
I want to send a put request to my API with multiple files and a JSON object. I don't want it to be post, I don't mind using JQuery AJAX call or any JavaScript AJAX call. Is it possible?