【问题标题】:Dajaxice: Something went wrong.达贾西斯:出了点问题。
【发布时间】:2014-10-26 05:30:54
【问题描述】:

我正在使用 PyCharm(DJango 框架的 IDE),它似乎可以工作,但我有这个错误

error: [Errno 10053] An established connection was aborted by the software in your host machine

当我点击Dajaxice 回调按钮时,当我查看控制台时,它显示

Dajaxice: Something went wrong. 

这是模板:

 <input type="submit" class="btn btn-primary" value="Display" id="showbutton" onclick="Dajaxice.tbl.sayhello(my_js_callback);">

由于某种原因,我的应用名称是 tbl

ajax.py

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

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

url.py

from django.conf.urls import patterns, include, url
from dajaxice.core import dajaxice_autodiscover, dajaxice_config
dajaxice_autodiscover()
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
                   url(r'^$', 'tbl.views.display_maps', name='home'),
                   url(r'^admin/', include(admin.site.urls)),
                   url(r'^accounts/auth/$', 'tbl.views.auth_view'),
                   url(r'^accounts/logout/$', 'tbl.views.logout'),
                   url(r'^profile/$', 'tbl.views.user_profile'),
                   url(r'^accounts/loggedin/$', 'tbl.views.loggedin'),
                   url(r'^accounts/invalid/$', 'tbl.views.invalid_login'),
                   url(r'^landinfo$', 'tbl.views.landpin_info'),
                   url(r'^simple-autocomplete/', include('simple_autocomplete.urls')),
                   url(dajaxice_config.dajaxice_url, include('dajaxice.urls')),
                )

我不知道怎么了。我遵循了 Dajaxice 的文档,但在运行应用程序时再次出现此错误。

self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine

【问题讨论】:

  • 我目前也有同样的问题

标签: python django pycharm dajaxice


【解决方案1】:

dajaxice 的“出现问题”错误消息可能是由各种问题引起的,包括 Python 函数中缺少或拼写错误的参数名称或 JavaScript 函数中生成的异常。但是,您的示例非常简单。 python 函数中没有命名参数,并且您没有提供 JavaScript 函数的代码。您的示例遵循我在自己的代码中调试和纠正的类似问题的模式。

这与提交按钮的 onclick 处理程序的使用有关。我相信,在服务器处理提交表单生成的 POST 请求的同时,从提交按钮处理程序进行 ajax 调用会在服务器上启动异步活动。我相信服务器在完成对 ajax 调用的响应之前看到了 POST 请求,并且 POST 抢占了 ajax 调用,从而导致了 dajaxice 错误消息。

调试和找到根本原因相当复杂,但我广泛使用了测试用例,并且可以使用 Safari 浏览器和 Django python 开发服务器始终如一地重现行为。

浏览器和服务器都必须处理异步消息才能使 ajax 调用正常工作。我对允许这种抢占的服务器可能是错误的。相反,它可能是您的浏览器。无论如何,最终结果都是一样的。

那么如何避免这个问题呢?在我的例子中,我在表单中添加了一个隐藏的输入元素,并将我将使用 ajax 发送的数据附加到该输入的值字段。然后,隐藏的数据会与其他表单数据一起自动发送到 POST 中,这些数据会在您提交表单时自动生成。

还有其他解决方案:通过ajax提交所有表单数据,并禁用表单数据的自动提交POST(Submitting HTML form using Jquery AJAX)。或者您可以使用一些与表单提交无关的事件通过 ajax 将数据发送到服务器。

【讨论】:

    【解决方案2】:

    你使用的是什么版本的 Django?

    Dajaxice 是一个死项目,不适用于 Django >1.5。 (见my other post。)

    【讨论】:

      猜你喜欢
      • 2013-10-28
      • 2013-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 2013-10-05
      • 1970-01-01
      相关资源
      最近更新 更多