我有这个简单的 jQuery ajax 帖子到 Pyramid webapp。
阿贾克斯调用:
$.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");
}
});
金字塔路线:
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":"demo@something.com","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'
如果我遗漏了什么,请告诉我。谢谢