2013-09-29 168 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的原始工作中省略了右括號。