1
我是使用Java开发Web应用程序的新手。我正在尝试建立一个AJAX调用。这是我创建的一些任意代码。Servlet + jQuery/Ajax - 未知的令牌o
的Servlet
Map<String, String> testJson = new HashMap<String, String>();
String Key = "someKey";
String Value = "someValue";
testJson.put(Key, Value);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(new Gson().toJson(testJson));
}
jQuery的
$(document).on("click","#register-user", function(){
$.ajax({
type: 'GET',
url: 'Register',
success: function(data){
alert($.parseJSON(data));
}
});
return false;
});
回调函数的工作没有任何的Json所以AJAX是好的。但是当我尝试发回一个用Json编码的Java对象时,我得到一个“Uncaught exception。Unexpected token o”。我究竟做错了什么?
你能提供'data'的内容? – emesx