抱歉我的英文。如果我错了,请纠正我。 这个函数在firefox中正确执行但目标浏览器是chrome,我不知道错误
myjs.js
function addProduct(order_id) {
$.ajax({
type: "post",
data: $("#formProducts").serialize(),
url: "/save/" + order_id,
complete: function(){}
});
$.ajax({
type: "get",
url: "/add/product/" + order_id,
complete: function(){
window.location.reload()
},
});
}
views.py
def post(self, request: HttpRequest, *args, **kwargs):
order = Order.objects.get(id=int(kwargs['order_id']))
try:
comment = Comment.objects.get(order=order)
comment.text = request.POST['comment']
except Exception as _:
comment = Comment(text="", order=order)
comment.save()
for key, val in request.POST.items():
if "status" in key:
idp = int(key.split("status")[1])
product = Product.objects.get(id=idp)
product.status = val
product.save()
elif "provider" in key:
idp = int(key.split("provider")[1])
product = Product.objects.get(id=idp)
product.provider = val
product.save()
elif "med" in key:
idp = int(key.split("med")[1])
product = Product.objects.get(id=idp)
product.name = val
product.save()
elif "amount" in key:
idp = int(key.split("amount")[1])
product = Product.objects.get(id=idp)
product.amount = val
product.save()
elif "cost" in key:
idp = int(key.split("cost")[1])
product = Product.objects.get(id=idp)
product.cost = val
product.save()
elif "ITOG" in key:
order.summary = val
order.save()
url_ref = request.session["url_ref"]
return redirect(url_ref)
def addProduct(request: HttpRequest, order_id):
order = Order.objects.get(id=int(order_id))
product = Product(name="", amount=1, cost=0.0, order=order)
product.save()
return HttpResponse()
函数必须收集formdata并发布它。然后make get request并重新加载页面。 Chrome可以实现,但重新加载页面后我看不到保存的数据,我必须重新加载页面,然后才能看到保存数据。
谢谢你的宁静。你的答案是对的
答案 0 :(得分:-1)
您可以使用此结构
$(document).on('click','.sendwork',function(e){
$.ajax({
type: "post",
data: $("#formProducts").serialize(),
url: "/save/" + order_id,
complete: function(){}
});
$.ajax({
type: "get",
url: "/add/product/" + order_id,
complete: function(){
},
});
window.location.reload()
});