B
B
blackVirus2022-03-25 15:57:32
PHP
blackVirus, 2022-03-25 15:57:32

How to send an ajax variable and accept it on the page?

In general, I'm trying to figure out the lesson, I threw it like this

var CategoryVariable = "Text"

$.ajax({
            url: "/resources/views/pages/AdminPanel/AddForm.blade.php",//по идее путь к странице
            type: "POST",
            dataType: "html",
            data: {key: CategoryVariable},
            error: function (){
                alert('Ошибка. Данные не отправлены.');
            },
        })

how to accept this data on the page now? And write them into a variable, $resultI know that they need to be accepted somehow, {{$result = json_encode(данные)}}but I don’t understand exactly how, so far, tell me please)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pLavrenov, 2022-03-26
@pLavrenov

AddForm.blade.php is the template file.
The URL is set in the /routes
folder My advice, read the entire laravel documentation from start to finish, it is not long, but it will immediately become clear what it can do and where to look if anything. You can also find examples there.
The route refers to the controller, and the controller, in turn, receives the Request object in which the transmitted data is located, at the same time, the controller returns what needs to be received via this route.
Laravel - routing
What is MVC to understand what is going on there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question