Home > front end >  Ajax for less than the send method the background parameters
Ajax for less than the send method the background parameters

Time:09-27

Ajax code is written so
//1. Create an AJAX core object XMLHttpRequest (built-in browser object, can be used directly)
Var XHR=null;
If (window. The XMLHttpRequest) {
XHR=new XMLHttpRequest ();
} else {
XHR=new ActiveXObject (" Microsoft. XMLHTTP ");
}
//2. The registered callback function
XHR. Onreadystatechange=function () {

}
//3. Open the passage between the browser and server
XHR. Open (" POST ", "login. Do", true);
XHR. SetRequestHeader (" Context - Type ", "application/x - WWW - form - urlencoded; charset=UTF-8");
//4. Sending an AJAX request
XHR. Send (" username="+ username +" & amp; Password="+");
This is the server code:
Public class LoginServlet extends the HttpServlet {
Protected void doPost (it request, HttpServletResponse response) throws ServletException, IOException {

String username=request.getParameter("username");
String password=request.getParameter("password");

}

When debugging the username and password values always null

CodePudding user response:

Get less than parameter, is the problem field, if it is a post request, the back-end requestbody is used to receive, also is the need to json format, check whether the console network is contentType: "application/json"

CodePudding user response:

In the browser F12 developer tools - network - tracking the url to request data right
  •  Tags:  
  • Ajax
  • Related