このシンプルな jQuery ajax を Pyramid webapp に投稿しています。
Ajax 呼び出し:
$.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' で起動し続けます
何か足りない場合は教えてください。ありがとう