$('#loginForm').submit(function(e){
var $inputs = $(this).find("input");
var serializedData = $(this).serialize();
$inputs.prop("disabled", true);
var request = $.ajax({
url: "myurl",
dataType: "json",
type: "GET",
data: serializedData,
});
request.done(function (response, textStatus, jqXHR){
$('#loginMessage').text('GOOD');
});
request.fail(function (jqXHR, textStatus, errorThrown){
$('#loginMessage').text('Some error occured. Please try again');
console.error("The following error occured: ",errorThrown,jqXHR);
});
request.always(function () {
$inputs.prop("disabled", false);
});
// prevent default posting of form
e.preventDefault();
});
我是 jquery 的新手,在上面的代码中 .done 块没有执行,firebug 控制台显示此消息:-
GET myurl?userID=aman&password=aman
200 OK 37ms jquery....min.js(第 2 行)
发生以下错误:(空字符串)Object { readyState=0, status=0, statusText="error"}
服务器端脚本
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("userID");
String password = request.getParameter("password");
System.out.println("GET");
response.setContentType("application/json");
PrintWriter out = response.getWriter();
Gson gson = new Gson();
if(username.equals("aman") && password.equals("aman")){
out.println(gson.toJson(new Boolean("true")));
}else{
out.println(gson.toJson(new Boolean("false")));
}
out.close();
}