2013-05-12 87 views
0

有人可以帮助我确定以下请求出了什么问题。即使在服务器端我只是返回一个空白页面,我仍然不断收到软件中止!这是我甚至没有阅读请求后的内容。当我使用表单发布方法发送HTTP发布请求时,而不是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); 
       } 
      });    

在服务器端(蟒蛇-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

你是什么意思, “在服务器端软件中止请求”?服务器端发生了什么? – Brad 2013-05-12 04:42:05

+0

嗨布拉德,请看服务器代码和软件中止错误更新的问题。我正在提交一个其textarea被命名为“反馈”的表单。但是在中止之后,有一个自动获取'?feedback =“<任何我输入的输入框'''附加到原始URL并且有一个自动GET。不知道为什么GET发生了(不在服务器端发生,并且ajax代码就是上面写的,所以不知道GET是谁的!) – 2013-05-12 05:06:27

+0

@ dev-vb:删除了我的答案。它的其他东西在你的服务器端代码。 – mithunsatheesh 2013-05-12 05:08:05

回答

0

最后,找到了答案。简直不敢相信我花了几乎整整一天的时间来鉴别这个!

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

jQuery代码:

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

因为缺少 “返回false” 语句的和,我也陷入了各种各样的问题。

的html代码:

<form class="submit-feedback"> 
    <textarea name="feedback" placeholder="add text."></textarea> 
    <button> 
      Send Feedback 
    </button> 
</form>