-1

朋友们,我真的吓坏了,不要安装这个应用程序 dajax django 现在尝试手动安装,但什么也没做,想法是从模板发送,给定一个变量并返回相同的变量作为警告,欢迎帮助我这个疯狂的人。

<script type="text/javascript">
    var name = 'Joe';
    function my_js_callback(){
        $.ajax({
            type:"POST",
            url:"/app/test",
            data: {
                    'name': name
            },
            success: function(data){
                alert(data);
            }
        });
    }
    </script>

@login_required
def app_test(request):
    if request.is_ajax():
        name = request.POST.getlist('name')[0]
        message = name
    else:
        message = "Not Ajax"
    return HttpResponse(message)
4

1 回答 1

0
vista
----------------------------------------------------
@csrf_exempt
@login_required
def app_test(request):
    if request.is_ajax():
        if request.method == 'POST':
            info = '"%s"' % request
            return HttpResponse(info)


html
----------------------------------------------------
    <script type="text/javascript">
        var myEvent = {id: '12345', end: '12345', allDay: '12345'};
        function my_js_callback(){
            $.ajax({
                url: '/app/test/',
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                data: $.toJSON(myEvent),
                dataType: 'text',
                success: function(result) {
                    console.log(result);
                    alert('OK');
                }
            });
        }
    </script>
于 2013-04-11T23:42:56.990 回答