无法在Djang中的jqueryajax post调用上获取视图的值

2024-09-28 19:25:32 发布

您现在位置:Python中文网/ 问答频道 /正文

单击按钮,我进行jqueryajax post调用,但在视图中它没有获取值。代码如下:

你知道吗jquery:-你知道吗

$("#startSimulator").click(function(){

        test = $("#testRange").val();
        gameKey = ($('input:radio[name=radioGroup]:checked').val() || 0);


        $("#imageLoading").css("display", "block");
        $.post("/blackout/setup/",{d : d,test : test,gameKey : gameKey}, function(data){


            $("#result").append(data);

        });

    });

你知道吗网址.py地址:

urlpatterns = patterns('',
            (r'^blackout/setup/$', 'blackout.views.setup'),
            )

你知道吗视图.py地址:

def setup(request):
    gameKey = request.POST['gameKey']
    test = request.POST['test'] 
    data = request.POST['d']

    #Some other code

    #And then HttpResponse(data)

你知道吗错误:-你知道吗

Exception Value:    
"Key 'gameKey' not found in <QueryDict: {}>"


/home/dhruv/blackout_new_project/blackout/blackout_proj/blackout/views.py in setup
    gameKey = request.POST['gameKey'] 

Tags: inpytest视图datarequest地址setup
1条回答
网友
1楼 · 发布于 2024-09-28 19:25:32
    gameKey = ($('input:radio[name=radioGroup]:checked').val() || 0);

这到底是怎么回事?我想这可能是问题所在,我不确定radiobox是否正确,但是如果没有设置,checkbox会在checked属性上返回null或未定义(不记得确切是哪一个)。你知道吗

在进行ajax调用之前检查gameKey的值。你知道吗

相关问题 更多 >