weixin_33714884 2013-04-11 00:30 采纳率: 0%
浏览 47

django,ajax,jquery

friends, I'm really freaking out, do not install this application dajax django and now try to do it manually and nothing to make it, the idea is to send from the template, given a variable and return the same variable as a warning, would welcome help me this crazy.

<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)
  • 写回答

1条回答 默认 最新

  • weixin_33713350 2013-04-11 23:42
    关注
    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>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料