简体   繁体   English

Dajax Hello World

[英]Dajax Hello World

I can't seem to get a simple hello world response from Dajax, after all day of working on hello world. 经过一整天的hello world工作之后,我似乎无法从Dajax得到一个简单的hello world反应。 (I'm sure you'll realize that this is word for word from the hello world guide) (我相信您会意识到,这是来自“ hello world guide”的逐字逐句说明)

I have an apps folder Example: proj/apps/myapp 我有一个apps文件夹例如:proj / apps / myapp

I have created ajax.py inside of 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'})

I have my template: 我有我的模板:

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

This doesn't work. 这行不通。 I have also followed the installation guide word for word found: http://django-dajaxice.readthedocs.org/en/latest/installation.html 我还按照安装指南中的单词搜索: http : //django-dajaxice.readthedocs.org/en/latest/installation.html

Any help would be greatly appreciated. 任何帮助将不胜感激。 I feel like I'm losing my mind. 我感觉好像迷失了方向。

OP在最初的努力中省略了一个结束括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM