有人可以帮我确定以下请求的错误。即使在服务器端我只是返回一个空页面,我一直在软件中止!那是我甚至没有阅读后请求的内容。当我使用表单post方法发送HTTP post请求时,而不是ajax,这一切都很好。所以我相信没有服务器问题。
谢谢!
$.ajax({
type: 'post',
url: "/ajax/feedback",
data: JSON.stringify(["Add","1","2"]),
contentType: 'application/json',
dataType: 'json',
success: function(resp){
alert("Success. Server said:\n '" + resp + "'");
},
error: function(e){
alert('There is an Error: ' + e);
}
});
在服务器端(python-GAE)我所做的就是以下内容:
def post(self):
logging.info('in post REQUEST request handler')
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write("received!")
我得到的错误如下:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python25\Lib\SocketServer.py", line 222, in handle_request
self.process_request(request, client_address)
File "C:\Program Files (x86)\Python25\Lib\SocketServer.py", line 241, in process_request
self.finish_request(request, client_address)
File "C:\Program Files (x86)\Python25\Lib\SocketServer.py", line 254, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2780, in __init__
BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "C:\Program Files (x86)\Python25\Lib\SocketServer.py", line 521, in __init__
self.handle()
File "C:\Program Files (x86)\Python25\Lib\BaseHTTPServer.py", line 316, in handle
self.handle_one_request()
File "C:\Program Files (x86)\Python25\Lib\BaseHTTPServer.py", line 310, in handle_one_request
method()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2794, in do_POST
self._HandleRequest()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3090, in _HandleRequest
raise e
error: (10053, 'Software caused connection abort')
答案 0 :(得分:0)
最后,找到了答案。简直不敢相信我花了差不多一整天来识别这个!
问题是我在拦截html表单的提交按钮点击后没有返回“false”。
jQuery代码:
$('.submit-feedback > button').click(function(){
$.ajax(...); // same as in the question above
return false; // <-- THIS WAS MISSING
});
由于缺少“返回虚假”声明,我遇到了各种各样的问题。
HTML代码:
<form class="submit-feedback">
<textarea name="feedback" placeholder="add text."></textarea>
<button>
Send Feedback
</button>
</form>