Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何防止jquery mobile在django中使用ajax处理post请求_Jquery_Python_Django_Mobile - Fatal编程技术网

如何防止jquery mobile在django中使用ajax处理post请求

如何防止jquery mobile在django中使用ajax处理post请求,jquery,python,django,mobile,Jquery,Python,Django,Mobile,我在为django项目集成jquery mobile时遇到了问题。尤其是jquery mobile(JQM)的登录功能似乎不是现成的。JQM使用ajax来处理post请求,这是我想要阻止的。在这个网站上 我读到有可能通过添加 数据json=“false” 但我该在哪里补充呢?在模板中还是在视图中?我尝试了不同的变化,但没有效果 以下是我的登录视图: def login(request): if request.method == 'POST': usern

我在为django项目集成jquery mobile时遇到了问题。尤其是jquery mobile(JQM)的登录功能似乎不是现成的。JQM使用ajax来处理post请求,这是我想要阻止的。在这个网站上

我读到有可能通过添加

数据json=“false”

但我该在哪里补充呢?在模板中还是在视图中?我尝试了不同的变化,但没有效果

以下是我的登录视图:

def login(request):        
    if request.method == 'POST':
        username = request.POST['u']
        password = request.POST['p']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                auth_login(request, user)
                msg.append("Hello %s your login was successful"% username)
        return HttpResponseRedirect('/profile/')
            else:
                msg.append("disabled account")
        else:
            msg.append("invalid login")

    return render_to_response('login.html') 
模板如下所示

    {% block content %}

        <form action="" method="post">{% csrf_token %}
            Login:&nbsp; <input type="text" name="u">
            <br/>
            Password:&nbsp; <input type="password" name="p">
            <input  type="submit" value="Login">
        </form>
    {% if errors %}
        <ul>
            {% for error in errors %}
            <li>{{ error }}</li>
            {% endfor %}
        </ul>
    {% endif %}
    <a href="logout"> Logout </a>

{% endblock %} 
{%block content%}
{%csrf_令牌%}
登录:

密码: {%if错误%}
    {错误%中的错误为%0}
  • {{error}}
  • {%endfor%}
{%endif%} {%endblock%}
好的,我自己想出来的: 只需将此javascript片段添加到模板头中:

<script type="text/javascript">
    $(document).bind("mobileinit", function(){
    ajaxEnabled:false;    
    });
    </script> 

$(document).bind(“mobileinit”,function(){
ajaxEnabled:false;
});