我正在使用Sinatra来托管一个简单的服务。以下是我的整个应用程序:
require 'sinatra'
get '/hello' do
'Hello world!'
end
然后我在./public
目录下有一个单独的html文件,尝试对我的服务进行GET请求:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function(event) {
$.get("/hello", function() { alert("first success"); })
.success(function() { alert("second success"); })
.error(function(jqXHR) { alert("error: " + jqXHR); });
})
});
</script>
</head>
<body>
<a href="">Link</a>
</body>
</html>
当我在HTML页面上点击链接时,我在服务器日志中看到以下内容:
``` 0:0:0:0:0:0:0:1%0 - - [16/Feb/2011 10:37:42] "GET /hello HTTP/1.1" 200 12 0.0030 localhost - - [16/Feb/2011:10:37:42 CST] "GET /hello HTTP/1.1" 200 12 Referer -> /hello ```
这看起来很好,但无论我怎样调整,我只能让错误回调被调用,从未成功过。
我的两个问题是: 1)我做错了什么? 2)我该如何调试此类问题?传递给错误回调的对象只是一个Object,并且我无法获取有关错误的信息。
谢谢!