【问题标题】:How to prevent jquery mobile from handling post request with ajax in django如何防止jquery mobile在django中使用ajax处理post请求
【发布时间】:2012-01-26 09:16:15
【问题描述】:

我无法为我的 django 项目集成 jquery mobile。特别是登录功能似乎不适用于 jquery mobile(JQM)。 JQM 使用 ajax 来处理我想要阻止的发布请求。在本站http://blog.vrplumber.com/index.php?/archives/2511-Miscellaneous-jQuery-Mobile-+-Django-tips.html

我读到可以通过添加来阻止 JQM 这样做

data-json="假"

但是我在哪里添加呢?在模板中还是在视图中?我尝试了不同的变化,但没有任何效果。

这是我的登录视图:

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 %} 

【问题讨论】:

    标签: jquery python django mobile


    【解决方案1】:

    好吧,我自己想通了: 只需将此 javascript sn-p 添加到您的模板头中:

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

    【讨论】:

      猜你喜欢
      • 2013-02-28
      • 1970-01-01
      • 2013-06-04
      • 2021-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      相关资源
      最近更新 更多