Django-is_ajax()不返回true [英] Django - is_ajax() not returning true

查看:38
本文介绍了Django-is_ajax()不返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道已经有很多问题要解决,但我无法解决.请看看:

I know there are a lot of questions already asked on this but I am not able to get around with it. Please have a look:

从配置文件视图中,当按下更新"按钮时,我希望用户以可编辑的形式显示,并具有从数据库中选取的值.因此,到目前为止,尚无POST数据.

from a profile view when "update" button is pressed I want the user to be displayed with an editable form with values picked from database. So as of now there is no POST data.

模板:

<form id="shw-form" action="/update_user_profile/{{r_user.id}}" method="get" enctype="multipart/form-data">
<button type="submit" id="upd-btn"  class="btn btn-lg btn-warning" onclick="update_profile_page();">UPDATE</button>
</form>

jquery:

<script type="text/javascript">
    function update_profile_page() {


            var form = $("#shw-form");
            $("#upd-btn").attr('disable', 'true');
            $.ajax({
                url: form.action,
                type: 'get',
                success: function(response){
                    $("#upd-main").load(response); 
                }
                });

            return false;

    }
   </script> 

urls.py

url(r'^update_user_profile/(?P<user_id>\d+)$', 'myapp.views.update_user_profile', name='update_user_profile')

但是当我单击按钮时,is_ajax()的else部分就会执行.

but when I click on the button the else part of is_ajax() is executed.

如果您发现我做错或遗漏的任何内容,请查看.谢谢.

Please have a look if you can find anything that I am doing wrong or missing. Thanks.

推荐答案

不要使用按钮的onclick属性,它可能无法捕获所有内容.改用jQuery的Submit()事件处理程序( http://api.jquery.com/submit/)如果您在控制台中看不到任何请求,那么Daniel很可能是对的:以通常的方式提交表单.

Don't use the onclick attribute of the button, it may not catch everything. Use jQuery's submit() event handler (http://api.jquery.com/submit/) instead.If you don't see any request in the console, then Daniel is very likely right: the form is submitted the usual way.

这篇关于Django-is_ajax()不返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆