我有一个 django 应用程序在 cpanel 的子域上运行。我遇到的挑战是我有不返回数据的ajax按钮

I have a django app running on a cpanel's subdomain. The challenge I am experiencing is I have ajax buttons that are not returning data

提问人:Prosper Pcyber Blade Mawire 提问时间:10/26/2023 更新时间:10/26/2023 访问量:15

问:

这是我 views.py `

def minuscreditcart(request):
    if request.method == 'GET':
        product_id = request.GET['prod_id']
        print(product_id)
        print("GET MINUS {}", product_id)
        c = CreditCart.objects.get(Q(ordered=False) & Q(product=product_id) & Q(customer=Customer.objects.get(user_account=request.user)))
        if c.quantity <=1:
            pass
        else:
            c.quantity -= 1
            c.save()
        cart = CreditCart.objects.filter(Q(customer=Customer.objects.get(user_account=request.user)) & Q(ordered=False))
        creditApp = Credit_Facility_Application.objects.get(Q(disclaimer=False) &Q(customer=Customer.objects.get(user_account=request.user)))
        instal = Instalment.objects.get(application_form=creditApp)
        amount = 0
        period = instal.period
        deposit = instal.deposit
        period = int(period)
        customer = Customer.objects.get(user_account=request.user)

        try:
            employment = Employment_detail.objects.get(customer=customer)
            employmentInfo = EmploymentForm(instance=employment)
            net_salary = employment.net_salary
            credit_limit = net_salary * 0.25
            creditlimit = credit_limit
        except:
            credit_limit = False
            employmentInfo = EmploymentForm()

        admincharge = 0.03 ;
        mothlycharge = 0.08; 
        ssbcharge = 0.05;
        for p in cart:
            value = p.quantity * p.product.discount_price
            amount = amount + value
        totalamount = amount
        
        balance = (1 + admincharge) * totalamount;
        depositlimit = int(balance * 0.3);
        balance = balance - deposit;

        totalmonthlycharges = mothlycharge * period;

        aftermonthlycharges = (1 + totalmonthlycharges) * balance;

        totalamount = ((1 + ssbcharge) * aftermonthlycharges)
        instalment = (totalamount / period)

                myinstalment = round(instalment, 2)
        data = {
            'quantity':c.quantity,
            'amount':amount,
            'totalamount':totalamount,
                'myinstalment':myinstalment,
            'period':period,
            'depositlimit':depositlimit,
            }
        return JsonResponse(data)

这是相应的 ajax 代码


$('.minus-credit-cart').click(function(){
    var id=$(this).attr("pid").toString();
    var eml=this.parentNode.children[2];

    $.ajax({
        type:"GET",
        url:"/minus-credit-cart",
        data:{
            prod_id:id

        },
        success:function(data){
            eml.innerText=data.quantity 
            document.getElementById("amount").innerText=data.amount;
            document.getElementById("totalamount").innerText=data.myinstalment;
            document.getElementById("period").innerText=data.period;
            document.getElementById("depositamount").innerText = data.depositlimit;
            document.getElementById("depo").innerText = "Deposit Limit";
            mydep = document.getElementById("deposit");
            mydep.setAttribute("min", data.depositlimit);
            mydeplim = document.getElementById("depositlimit");
            mydeplim.setAttribute("value", data.depositlimit);
        }
    })
})

我希望我的代码在单击减号按钮时从信用车中减去一个项目,加号按钮也应该发生同样的情况。

在开发环境中,代码运行平稳且良好。 这些按钮使用 GET 方法访问数据库。 提交到数据库后,应返回结果。

Django Ajax 部署 子域 cPanel

评论


答: 暂无答案