The reason why only the existing page comes out?

Asked 2 years ago, Updated 2 years ago, 77 views

Hello, I'm a person who just started learning coding. I'm making a simple shopping mall. If I press 4 products on the main page of the shopping mall, I am trying to change the value within the same page. But if I press it, it keeps getting the same value.

    <script type="text/javascript">
        $(document).ready(function () {
            console.log(123123)
            product = window.location.href
            product_link = product.split('=')
            console.log(product.split('='))
            console.log(window.location.href)
            detail_page(product_link[1])
        })

        function detail_page(product_id) {
            console.log(123)
            $.ajax({
                type: "GET",
                url: "/detail?product=" + product_id,
                data: {},
                success: function (response) {
                    console.log(response);
                    let product_info = response['product_info'];
                    make_card(product_info['price'], product_info['code'], product_info['supply'], product_info['delivery'], product_info['tprice'])

                }
            })
        }

If you look at the console inside the page, you get data, but why is that? [Console window]

(2) ["http://localhost:5000/product_detail?product", "product4"]
0: "http://localhost:5000/product_detail?product "
1: "product4"
length: 2
__proto__: Array(0)
product_detail?product=product4:30 http://localhost:5000/product_detail?product=product4 
product_detail?product=product4:35 123
product_detail?product=product4:41 
{msg: "You have accessed the details page.", ", product_info: {…}, }, result: "success"}
msg: "You have accessed the detail page."
product_info: {Tprice: 20900, code: "C004890", coupon: "0 pieces", delivery: "free shipping", name: "product4", …}
result: "success"
__proto__: Object

flask python html ajax

2022-09-21 10:16

1 Answers

Isn't product_id different for each product? Based on the current code alone, it seems that you are requesting only one ID repeatedly. If the product changes, try to change the product_id as well.


2022-09-21 10:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.