我正在 Perl Web 框架中构建一些 ajaxDancer
我不确定它是否使用正确的 http 标头进行响应,因为我无法从看似成功的请求中触发 jQuery 的 ajax 成功处理程序。使用下面的 ajax 片段,我在浏览器控制台中得到以下输出。完整的回调被成功调用并给出看起来像成功的输出。Status:200 StatusText:"OK"
然而,成功处理程序永远不会被调用。
$.ajax({type: "GET", url: "/learn/faq",
success: function(data){console.log('omg got it');},
complete: function(data){console.log("complete", data);}
}).success(function(data){console.log('defered');});
Object
XHR finished loading: "https://www.localhost:4443/learn/faq". assets-d36e1bb9fd59ba3dbd0f8a0cbb37ed8e.js:1
complete
Object {readyState: 4, responseText: "↵↵<!DOCTYPE html>↵<html xmlns="http://www.w3.org/1…ead/conversion.js"></script>↵↵↵↵</body>↵</html>↵↵", status: 200, statusText: "OK"
我应该看到omg got it
anddefered
消息,但不是。看着这个,我觉得 jQuery 成功处理程序比状态和 Dancer http 实现没有正确响应更多。
此外,我已经error
向片段添加了一个处理程序,并且错误处理程序被触发,看起来像是一个成功的请求。
$.ajax({type: "GET", url: "/learn/faq",
success: function(data){console.log('omg got it');},
complete: function(data){console.log("complete", data);},
error: function(data){console.log("error!", data);}
}).success(function(data){console.log('defered');});
Object
XHR finished loading: "https://www.localhost:4443/learn/faq". assets-8cd028b93e0db9dd9455125dc98d5ae1.js:1
error!
Object {readyState: 4, responseText: "↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵<!DOCTYPE html>↵<html xmlns="http:…></script>↵↵↵↵</body>↵</html>↵↵↵↵</body>↵</html>↵", status: 200, statusText: "OK"}
complete
Object {readyState: 4, responseText: "↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵<!DOCTYPE html>↵<html xmlns="http:…></script>↵↵↵↵</body>↵</html>↵↵↵↵</body>↵</html>↵", status: 200, statusText: "OK"}
以下是来自的响应标头jQuery getAllResponseHeaders()
complete Date: Tue, 01 Jan 2013 22:43:52 GMT
Content-Encoding: gzip
X-Powered-By: Perl Dancer 1.3095.1
Transfer-Encoding: chunked
Connection: keep-alive
Server: nginx/1.2.4
Strict-Transport-Security: max-age=2592000
Content-Type: text/xml; charset=utf-8