首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Smoothstate.js和Django -表单帖子只在第二次单击时触发

Smoothstate.js和Django -表单帖子只在第二次单击时触发
EN

Stack Overflow用户
提问于 2016-10-01 16:53:58
回答 1查看 614关注 0票数 1

我目前正在尝试将Smoothstate.js集成到我的Django项目中。我正在使用来自smoothstate.js github站点的js代码片段。

代码语言:javascript
复制
$(function(){
  'use strict';
  var options = {
    prefetch: true,
    cacheLength: 2,
    onStart: {
      duration: 250, // Duration of our animation
      render: function ($container) {
        // Add your CSS animation reversing class
        $container.addClass('is-exiting');

        // Restart your animation
        smoothState.restartCSSAnimations();
      }
    },
    onReady: {
      duration: 0,
      render: function ($container, $newContent) {
        // Remove your CSS animation reversing class
        $container.removeClass('is-exiting');

        // Inject the new content
        $container.html($newContent);

      }
    }
  },
  smoothState = $('#main').smoothState(options).data('smoothState');
});

我的模板看起来如下(为了这个问题,我简化了它):

代码语言:javascript
复制
<head>
{% load static %}
<script src="{% static 'js/vendor/jquery.js' %}"></script>
<script src="{% static 'js/vendor/what-input.js' %}"></script>
<script src="{% static 'js/vendor/foundation.js' %}"></script>
<link rel="stylesheet" href="{% static 'css/foundation.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
    <div id="main" class="m-scene">
        <!--...-->
        <div class="row expanded collapse">
            <div class="scene_element scene_element--fadeinright large-12 columns">
                <a href="{% url 'transition' %}">test</a>
                <form action="{% url 'transition' %}" method='POST'>
                    {% csrf_token %}
                    {{form}}
                    <input type="submit" class="button green" value="join"></input>
                </form>
            </div>
        </div>
    </div>


    <script src="{% static 'js/jquery.smoothState.js' %}"></script>
    <script src="{% static 'js/initSmoothState.js' %}"></script>
</body>

当我单击链接时,Smoothstate.js的工作方式与预期的一样。但当我提交表单时,它不会发送帖子,只会触发动画。当我第二次点击它时,它会发送帖子并按它应该的方式工作。

有什么想法吗?

编辑

我在smoothstate.js上发现了这两个问题:第189期第231期

两者都是关于这个问题的,如果一个form POST action指向same URI,那么POST永远不会发送。当我将表单缓存设置为true时,我可以重新创建这种行为。

当我将其设置为false并将POST action指向一个different URI时,POST将按应有的方式发送。将其设置为不带same URIform caching会使我回到原来的问题。

这是Smoothstate.js中的一个bug吗?我看不出这是从django那里来的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-11 01:49:03

我在smoothstate.js github页面上也问过同样的问题。这似乎是唯一的解决办法是黑名单的形式。

代码语言:javascript
复制
$('#main').smoothState({ blacklist: '.no-smoothState' });

<form class="no-smoothState">
  ...
</form>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39809205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档