尽管 Pyramid 确实返回了响应,但未调用 jQuery.ajax 成功回调

发布于 2024-11-19 04:08:46 字数 1790 浏览 2 评论 0原文

我将这个简单的 jQuery ajax 发布到 Pyramid Web 应用程序。

Ajax 调用:

$.ajax({
     type: 'POST',
     url: 'http://localhost:6543/test',
     dataType: 'json',
     data: JSON.stringify({"username":"demo","email":"[email protected]","Password":"1234"}),
     success: function (response) {
        alert(response);
     },
     error: function (msg) {
         alert("error");
     }
});

金字塔路线:

config.add_route('test', 'test')
config.add_view('tagzu.views.test', route_name='test', renderer='json')

金字塔视图:

def test(request):
    return {'content':'Hello!'}

现在当我调用服务时,我发送此

请求:

POST /test HTTP/1.1
Host: localhost:6543
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 66
Origin: null
Pragma: no-cache
Cache-Control: no-cache

{"username":"demo","email":"[email protected]","Password":"1234"}

并且得到此响应:

HTTP/1.0 200 OK
Server: PasteWSGIServer/0.5 Python/2.7.1
Date: Fri, 08 Jul 2011 01:42:33 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 21

{"content": "Hello!"}

问题是:

ajax 成功处理程序从未被调用。 只有错误处理程序不断触发错误 msg.statusText = 'error'

如果我遗漏了什么,请告诉我怎么办。 谢谢

I have this simple jQuery ajax post to a Pyramid webapp.

Ajax call:

$.ajax({
     type: 'POST',
     url: 'http://localhost:6543/test',
     dataType: 'json',
     data: JSON.stringify({"username":"demo","email":"[email protected]","Password":"1234"}),
     success: function (response) {
        alert(response);
     },
     error: function (msg) {
         alert("error");
     }
});

Pyramid Route:

config.add_route('test', 'test')
config.add_view('tagzu.views.test', route_name='test', renderer='json')

Pyramid view:

def test(request):
    return {'content':'Hello!'}

now when I call the service, I am sending this

Request:

POST /test HTTP/1.1
Host: localhost:6543
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 66
Origin: null
Pragma: no-cache
Cache-Control: no-cache

{"username":"demo","email":"[email protected]","Password":"1234"}

and I get this reponse:

HTTP/1.0 200 OK
Server: PasteWSGIServer/0.5 Python/2.7.1
Date: Fri, 08 Jul 2011 01:42:33 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 21

{"content": "Hello!"}

Problem is:

the ajax success handler is never been called.
Only the error handler keeps firing with an error
msg.statusText = 'error'

Please let me know what if I am missing something.
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞琼窗梦回ˉ 2024-11-26 04:08:46

然而,遇到了和我一样的问题,即。睡眠不足!!

看在上帝的份上,确保 html 位于同一服务器上,因为发生这种情况是因为跨域调用,当然,带有 jQ​​uery 的 html 只是一个本地文件,服务在本地主机上提供。

因此,服务器拒绝了查询,没有任何错误详细信息来为我指明正确的方向。

跨域是我最不会想到的事情,因为太专注于 Pyramid,我认为它可能会做一些有趣的事情。
可笑的是,我浪费了这么多时间。

For however is encountering the same issue as me, ie. not having enough sleep!!

For the sake of God make sure the html is on the same server, as this happens because of calling across domains of course, the html with jQuery is just a local file, the service is served on localhost.

So the server was rejecting the query without any error details to point me in the right direction.

Cross-domain was the last thing I would have thought of, being too focused on Pyramid, I thought it might be doing something funny.
Funny me, for wasting so much time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文