Home > Back-end >  Ajax asynchronous verify account repetition
Ajax asynchronous verify account repetition

Time:09-27

Can you tell me whether I do an ajax asynchronous verify account why repeat what all don't show? Didn't found the problem, has set up a night
The script code:
 $(function () {
$(" # uname "). The onblur (function () {//when XXX loses focus
Var value=https://bbs.csdn.net/topics/$(" # uname "). Val ();//to get id for XXX element
$. Ajax ({
Url:/servlet/AjaxServlet,//to request the server url
Data: {value} "val" :,//it is an object, which represents the request parameter server can use request, getParamet () to obtain
If async: true,//for asynchronous request
Cache: false,//cache the results
Type: "POST",//request
DataType: "json",//what type the json data is returned from the server: receiving an object
Success: the function (result) {//this function can be carried on the server when success is called, parameters, the result is, the value of the server returns
If (result) {
Document. The getElementById (" notice "). The innerText="existing";
} else {
Document. The getElementById (" notice "). The innerText="hh";
}
}
});
});
});

The JSP code:
 & lt; The form action="ZuCe_result. JSP method=" post "" name=" frm_register & gt;" 

User name: & lt;/td>


The servlet code:
 @ WebServlet ("/AjaxServlet ") 
Public class AjaxServlet extends the HttpServlet {
Private static final long serialVersionUID=1 l;

/* *
* @ see HttpServlet# HttpServlet ()
*/
Public AjaxServlet () {
Super ();
//TODO Auto - generated constructor stub
}

/* *
* @ see HttpServlet# doGet (it request, HttpServletResponse response)
*/
Protected void doGet (it request, HttpServletResponse response) throws ServletException, IOException {
//TODO Auto - generated method stub
request.setCharacterEncoding("utf-8");
The response. SetCharacterEncoding (" utf-8 ");
The String value=https://bbs.csdn.net/topics/request.getParameter (" val ");//in adjx data set
UserDao dao=new UserDao ();
Boolean rs=dao. IsExitUname (" value ");
If (rs) {
//use the jquery ajax callback function return value is the print the string
The response. GetWriter (). Print (" true ");
} else {
The response. GetWriter (). Print (" false ");
}

}

/* *
* @ see HttpServlet# doPost (it request, HttpServletResponse response)
*/
Protected void doPost (it request, HttpServletResponse response) throws ServletException, IOException {
//TODO Auto - generated method stub
DoGet (request, response);
}

}

CodePudding user response:

Is anyone here??

CodePudding user response:

You need to have a problem, the url request path is/servlet/AjaxServlet in ajax, you have to @ WebServlet ("/AjaxServlet "), less a servlet, then test you can break point, if the request is coming after the background you can see

CodePudding user response:

refer to the second floor dhacker1 response:
you need to have a problem, the url request path is/servlet/AjaxServlet in ajax, you have to @ WebServlet ("/AjaxServlet "), less a servlet, then test you can break point, if the request is coming after the background you can see
thank you!! , the problem in this, I was looking for ages
  • Related