gpt4 book ai didi

javascript - Ajax Django 空列表

转载 作者:行者123 更新时间:2023-11-30 17:22:12 25 4
gpt4 key购买 nike

我已经被这个问题困了好几天了,似乎找不到解决办法。我在谷歌和这里看过很多类似的问题,但似乎无法解决这个问题。我最接近的是我现在所拥有的。

基本上我想做的是,一旦用户点击“结帐”,就会打开一个 javascript 提示并询问结帐该项目的原因,然后紧随其后,询问授权人的姓名查看。

<script>
$(document).ready(function(){
$('.chkrclass1').click(function(event){
var authby;
var reason;
var chkr = $('.tdata:eq(3)').html();
if (chkr == "Out Stock") {
alert("This item has already been checked out!");
event.preventDefault();
}
if (confirm("Are you sure you wish to checkout this item?") == true) {
reason = prompt("Please enter your reason for taking the item.");
authby = prompt("Please enter who authorized the checkout.");


$.ajax({
url: '/book/checkout/',
type: 'POST',
data: {"ids": authby, "idss": reason}
traditional: true,
success: function(data){
alert('Checkout Success!');
//$("body").append(data);
}
});

if (reason == '') {
alert("You never entered a reason. Cancelling checkout...");
event.preventDefault();
}
if (authby == '') {
alert("You have not entered who authorized the checkout. Cancelling checkout...");
event.preventDefault();
}
} else {
event.preventDefault();
}
});
});
</script>

我知道代码非常简单,可以通过多种方式进行优化,但我仍在学习,希望能尽快实现。

在我看来

def bookcheckout(request):
chkoutcons = {}
bchkoutcons['ogphead'] = "OGPSS Inventory Database"
bchkoutcons['title'] = "Checkout Success"
bchkoutcons['thedate'] = datetime.datetime.now().strftime('%d-%m-%Y')
username = request.user.username
username = username.capitalize()
if username.endswith('ogpss'):
username = username[:-5]
bchkoutcons['username'] = username
auths = request.POST.getlist('ids[0]')
reasons = request.POST.getlist('idss[0]')
bookch = BookCheckout(bookcheckoutdate=datetime.datetime.today(), bookcheckoutby=request.user.username, bookauthby=auths, bookreason=reasons, bookid=bookitem)
bookch.save()
return render_to_response('checkoutsuccess.html', bchkoutcons, context_instance=RequestContext(request))

当我进入管理部分并查看结帐信息时,这些值只是空列表。

我也试过

request.POST("ids")

但是 get QueryDict 是不可调用的。正如我所说,还有很多东西要学。

谁能帮我解决我做错了什么?

最佳答案

POST 是一个字典。

request.POST["ids"]

关于javascript - Ajax Django 空列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24951335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com