[英]Ajax error not loading message
I am receiving an error not loading message when I click on my submit button on my login.html. 单击我的login.html上的“提交”按钮时,我收到一条未加载错误消息。 I don't have much experience with this and there are no error messages to point me in the direction to fix it.
我对此没有太多经验,也没有错误消息指出要解决的方向。 I have my login.html
我有我的login.html
<body>
<div id="log">
<h2>Login</h2>
<form method="post" action="login" class="form-1" accept-charset="utf-8" onsubmit="sendAjax()">
<input type="text" name="username" id="username" placeholder="Username"/><br/>
<input type="password" name="password" id="password" placeholder="Password"/><br/>
<input type="submit" value="Sign In"/>
</form>
</div>
</body>
which is called into a div in my index.html 在我的index.html中被称为div
$('#login').click(function(e){
$('#map-canvas').addClass("hidden");
$('#dMain').removeClass("hidden");
$('#dMain').load('html/login.html');
e.preventDefault();
my login servlet 我的登录servlet
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String username = request.getParameter("username");
String password = request.getParameter("password");
if(databaseConnection.checkUser(username, password))
{
RequestDispatcher rs = request.getRequestDispatcher("Welcome");
rs.forward(request, response);
}
else
{
out.println("Username or Password incorrect");
RequestDispatcher rs = request.getRequestDispatcher("login.html");
rs.include(request, response);
}
}
and my ajax function 和我的ajax功能
function sendAjax(){
var article = new Object();
article.username = $('#username').val();
article.password = $('#password').val();
$ajax({
url: "http://localhost:8080/FishingTrax/LoginServlet",
type: 'POST',
dataType: 'json',
data: JSON.stringify(article),
contentType: 'application/json',
mimeType: 'application/json',
success: function (data) {
},
error:function(data,status,er) {
alert("error: "+data+" status: "+status+" er:"+er);
}
});
};
I had two problems with my code, I was lacking the return prior to the sendAjax(). 我的代码有两个问题,在sendAjax()之前缺少返回值。 The define Ajax problem was due to missing a full stop in $ajax so it should be $.ajax
定义Ajax问题是由于缺少$ ajax中的句号,因此应该是$ .ajax
function sendAjax(){
var article = new Object();
article.username = $('#username').val();
article.password = $('#password').val();
$.ajax({
url: "http://localhost:8080/FishingTrax/LoginServlet",
type: 'POST',
dataType: 'json',
data: JSON.stringify(article),
contentType: 'application/json',
mimeType: 'application/json',
success: function (data) {
},
error:function(data,status,er) {
alert("error: "+data+" status: "+status+" er:"+er);
}
});
}; };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.