开发者

jQuery.ajax success callback not called although Pyramid did return response

I have this simple jQuery ajax post to a Pyramid weba开发者_运维知识库pp.

Ajax call:

$.ajax({
     type: 'POST',
     url: 'http://localhost:6543/test',
     dataType: 'json',
     data: JSON.stringify({"username":"demo","email":"demo@something.com","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":"demo@something.com","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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜