V
V
Vladimir Kokhan2019-09-26 18:39:35
Laravel
Vladimir Kokhan, 2019-09-26 18:39:35

How to get a variable in a template?

Good day everyone
I'm trying to make a quick view of the product in a modal window like on this site https://likadress.ru/.
I wrote a script for this

$(".element-view").on("click", function (e) {
        let id = $(this).attr("id_product");
        e.preventDefault();

        $.ajax({
            url: '/products/'+id,
            type: 'POST',
            dataType:"json",
            success(response){
                $(".modal_details").addClass("show-modal");              
            },
            error(){
                console.log("ERROR");
            }
        });
    });

Controller code
public function modal($id)
    {
         $product = Product::find($id);

       return response()->json($product);
    }

When I click on the button in the console, I get
{id: 53, title: "Брюки LB 52-071", alias: "bruki-LB-52-071-", meta_title: "Брюки LB 52-071", meta_description: "", …}

Here I need to get the id somehow in the modal window template. Tell me how to do it?
Or is there some other way to solve the problem?
Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question