0

有人可以帮我确定以下请求有什么问题。即使在服务器端我只是返回一个空页面,我也会不断收到软件中止!那就是我什至没有阅读后请求的内容。当我使用表单发布方法而不是 ajax 发送 HTTP 发布请求时,一切都很好。所以我相信没有服务器问题。

谢谢!!

         $.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')
4

1 回答 1

0

终于,找到了答案。不敢相信我花了几乎一整天的时间来识别这个!

问题是我在拦截 html 表单的单击提交按钮后没有返回“false”。

jQuery代码:

$('.submit-feedback > button').click(function(){
    $.ajax(...); // same as in the question above
    return false; // <-- THIS WAS MISSING
});

由于缺少“return false”声明,我遇到了各种问题。

html代码:

<form class="submit-feedback">
    <textarea name="feedback" placeholder="add text."></textarea>
    <button>
            Send Feedback
    </button>
</form>
于 2013-05-12T05:20:34.097 回答