0
  1. 我从 github 下载了最新的django-dajaxicezip 文件,然后解压缩。
  2. 然后我进入django-dajaxice-master/examples文件夹,运行'python manage.py runserver 13.122.241.172:80',(这是我电脑的ip)。

服务器正常启动。在这台服务器电脑上,我可以访问http13.122.241.172/,页面正常显示。然后我点击“你好”按钮,我可以得到正确的回应。

问题:

在我同事的电脑上,他的ip是13.122.242.16,他可以访问http13.122.241.172/,但是当他点击“你好”按钮时,没有任何反应!

调试:

然后我检查命令窗口,我看到当他单击按钮时,我的服务器从未收到“ GET /dajaxice/simple.hello/?argv=undefined HTTP/1.1”请求!我对这个问题感到非常困惑,并且已经研究了三天。任何人都可以帮助我吗?

笔记:

  • Django 版本是1.4.20.
  • Django 设置:调试=真。

我的同事可以访问http://www.dajaxproject.com/dajaxice/如果他单击“从服务器获取消息!” 他可以得到服务器的响应。

代码:

这是来自dajaxice 项目的相关代码:

index.html(模板)

{% load dajaxice_templatetags %}
<html>
<head>
{% dajaxice_js_import 'nocsrf' %}
</head>
<body>
    <button onclick="Dajaxice.simple.hello(function(d){alert(d.message);})">Hello</button>
    <button onclick="Dajaxice.simple.bye(function(d){alert(d.message);})">Bye</button>
    <button onclick="Dajaxice.more.complex.bye(function(d){alert(d.message);})">Complex Bye</button>
    <button onclick="Dajaxice.simple.lol(function(d){alert(d.message);})">LOL</button>
    <button onclick="Dajaxice.simple.get_args(function(d){alert(d.message);}, {'foo': 'var'})">GET args</button>
</body>
</html>

ajax.py

import json

from dajaxice.decorators import dajaxice_register


@dajaxice_register(method='GET')
@dajaxice_register(method='POST', name='other_post')
def hello(request):
    return json.dumps({'message': 'hello'})


@dajaxice_register(method='GET')
@dajaxice_register(method='POST', name="more.complex.bye")
def bye(request):
    raise Exception("PUMMMM")
    return json.dumps({'message': 'bye'})


@dajaxice_register
def lol(request):
    return json.dumps({'message': 'lol'})


@dajaxice_register(method='GET')
def get_args(request, foo):
    return json.dumps({'message': 'hello get args %s' % foo})

进步:

  • 感谢您对这个话题的帮助。我是这里的新手。Stackoverflow 真的是个好地方。
  • 现在我找到了问题的症结所在:在我的服务器计算机上,我使用的是 IE11,但在我同事的计算机上,他使用的是 IE9。如果他换成 Chrome 就可以了。但这仍然让我感到困惑,我该如何与其他只有 IE9 的人相处。
4

1 回答 1

0

我会尝试做的第一件事是确保 IE9关闭了兼容性视图。

另请注意,django-dajaxice 的作者本人不建议使用该包

总之,不。我在 4 年前创建了这个项目,作为一个很酷的工具,以解决我当时遇到的一个特定问题。

这些天使用这个项目是一个坏主意。

也许我现在更务实了,也许我对我的 django 项目应该如何与这样的库耦合的看法发生了变化,或者也许这些天我真的很珍惜 vanilla django 开发的纯粹性和简单性。

如果你想模仿这个项目的功能,你只需要一些简单的视图和 jQuery。

忘记添加更多不必要的复杂性。保持简单。

因此,我会考虑你是否真的需要 dajaxice,或者我可以用其他方式来做。

于 2015-05-14T12:31:39.960 回答