2013-09-29 165 views
0

我似乎无法从Dajax那里得到一个简单的hello world响应,在hello world上工作了一整天。 (我敢肯定你会意识到,这是一个字一个字来自世界您好指南)Dajax Hello World

我有一个apps文件夹示例:PROJ /应用/ MYAPP

我创建的myapp ajax.py内:

from django.utils import simplejson 
from dajaxice.decorators import dajaxice_register 

@dajaxice_register 
def sayhello(request): 
    return simplejson.dumps({'message':'Hello World'}) 

我有我的模板:

{% load dajaxice_templatetags %} 

<html> 
    <head> 
    <title>My base template</title> 
    ... 
    {% dajaxice_js_import %} 
    </head> 
    <script type="text/javascript"> 
    function my_js_callback(data){ 
     alert(data.message); 
    } 
    </script> 
    <input type="button" onclick="Dajaxice.myapp.sayhello(my_js_callback);" value="test"> 
</html> 

这是行不通的。我也按照安装指南一字找字:http://django-dajaxice.readthedocs.org/en/latest/installation.html

任何帮助将不胜感激。我觉得我正在失去主意。

+0

您是否正确地使用了dajax静态文件?我相信'dajaxice_js_import'会自动检查你的静态URL是否被正确配置,但是不能手动验证它。检查您的Web控制台是否正确加载了dajaxice js。 –

+0

@RomanAlexander是的,我已经在URL中设置了服务文件,我可以从runserver看到它正在适当地提取静态文件。 – moreisee

+0

我是个白痴。我忘了一个右括号。感谢@罗曼亚历山大查看它。 – moreisee

回答

0

在OP的原始工作中省略了右括号。