【问题标题】:Dajax example "Multiply Machine!" not working. HelpDajax 示例“乘法机!”不工作。帮助
【发布时间】:2011-09-06 15:51:45
【问题描述】:

尝试学习 Dajax,因此决定尝试示例。但我坚持使用“乘法”示例。我不知道出了什么问题。下面是代码。

ajax.py:(它放置在“博客”应用程序中)

from dajax.core import Dajax
from dajaxice.core import dajaxice_functions

def multiply(request, a, b):
    dajax = Dajax()
    result = int(a) * int(b)
    dajax.assign('#result','value',str(result))
    return dajax.json()

dajaxice_functions.register(multiply)

index.html:

{% load dajaxice_templatetags %}
<html>
    <head>

        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <title>Blog</title>
        {% dajaxice_js_import %}
        <script type="text/javascript" charset="utf-8">
             function calculate(){
                Dajaxice.blog.multiply(Dajax.process,{'a':$('a').value,'b':$('b').value})
              }
        </script>
    </head>
    <body>

        <input type="text" name="a" value="5" id="a"> x
        <input type="text" name="b" value="6" id="b"> =
        <input type="text" name="result" value="" id="result">
        <input type="button" name="caculate" value="Let's Multiply!" id="caculate" onclick="calculate()">

    </body>
</html>

【问题讨论】:

  • 你能告诉我你到底有什么错误吗?这是一个JS错误?你用的是什么版本的 dajax 和 dajaxice?
  • 没有错误。只是结果文本字段为空。不出现相乘值。我正在使用最新版本的 dajax n dajaxice。我需要使用任何 JS 框架(jquery 或原型)吗?

标签: ajax django django-templates


【解决方案1】:

首先你应该正确地install dajaxice。那么,如果你使用的是 Dajax,你也应该install Dajax

阅读您的代码似乎已正确安装了 dajaxice,但您尚未安装 Dajax 或(至少)您尚未链接您的 dajax 风格的 js。

如果您使用的是 Dajax(您正在使用 Dajax),您应该在 Prototype、jQuery、Dojo 或 mootols 之间选择一个框架并将其添加到您的页面,还需要将 framework.dajax.core.js 链接到您的页面。

其余的安装似乎已经完成了。

【讨论】:

    猜你喜欢
    • 2015-01-23
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多