这是我的代码:
$.ajax({
url: "MyServlet",
dataType: "json",
data: data,
type: "post",
cache: false
}).done(function (data) {
alert('hello');
}).fail(function (XMLHttpRequest, textStatus, errorThrown) {
alert('error: ' + XMLHttpRequest.status + ": " + XMLHttpRequest.responseText + ": " + textStatus + ": " + errorThrown);
});
而且我收到:“错误:200:parsererror:SyntaxError:输入意外结束”
我不知道为什么。有什么帮助吗?
我的servlet基本上返回以下内容:
PrintWriter out = response.getWriter();
JSONObject json = new JSONObject();
json.put("test", "hello servlet");
out.print(json);
out.close();
最佳答案
我已经弄清楚了。我没有正确关闭servlet中的out流,这导致返回了错误的json数据。