When I request a server, I get an error, from what I see, I get an empty object that cannot be parsed. Line 29 output "emptiness" what could be the problem? Does the “empty response” return or is it different?

$("#logger-button").click(function () { var loginData = { nickName:$("#user-name").val(), email:$("#email").val(), password:$("#password").val(), formId:$("#loginForm").val() } var JSONString = JSON.stringify(loginData); console.log(JSONString); var url = "http://localhost:8080/CouponProject/login"; $.ajax({ url:url, method:"post", data:JSONString, contentType:"application/json", error:function (message) { console.log(message); }, success:function (data) { console.log(data); // line 29 var JSONObject = JSON.parse(data); // line 31 console.log(JSONObject); }, headers: { "Accept":"application/json", "Accept-Language":"en", "Cache-Control":"max-age=3600" } }); 

Server code:

 protected static boolean postDatabase(String[] loginData, HttpServletResponse response) throws IOException { try { output = response.getWriter(); Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection(URL, USER_NAME, PASSWORD); String checkingUser = "SELECT nick_name,email,password FROM users WHERE nick_name=?"; PreparedStatement preparedStatement = connection.prepareStatement(checkingUser); preparedStatement.setObject(1, loginData[0]); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { int passwordColumn = resultSet.findColumn("password"); int emailColumn = resultSet.findColumn("email"); System.out.println(passwordColumn); System.out.println(emailColumn); System.out.println(resultSet.getString(passwordColumn)); // correct System.out.println(resultSet.getString(emailColumn));// correct if (resultSet.getString(passwordColumn).equals(loginData[1])) { System.out.println(resultSet.getString(passwordColumn)); if (resultSet.getString(emailColumn).equals(loginData[2])) { ResponseDataHandler.ToJSONresponse("success", response); } } } } catch (IOException ioError) { ResponseDataHandler.ToJSONresponse(ioError.toString(), response); } catch (ClassNotFoundException notFound) { ResponseDataHandler.ToJSONresponse(notFound.toString(), response); } catch (SQLException sql) { ResponseDataHandler.ToJSONresponse(sql.toString(), response); } finally { try { connection.close(); } catch (SQLException sql) { ResponseDataHandler.ToJSONresponse(sql.toString(), response); } } return false; } 

enter image description here

enter image description here

  • Comments are not intended for extended discussion; conversation moved to chat . - Nicolas Chabanovsky

1 answer 1

Obviously - the data empty, judging by the conclusion above error, which means it is not valid JSON .
Why returning an empty string (or white space) is an interesting (perhaps), but completely different question.

  • What is the meaning of the answer, nothing to answer? I see that it is not valid JSON .. So what could be wrong? I will listen to you with pleasure .. What should I drop from the pollack server? After sending the request through the login form, the data comes to the server and I can print them to the console .. But back I automatically receive this kind of error in the Google console .. There are not any Exepshions on the server .. When sending a request, for example, with the form register everything is fine .. - Maks.Burkov
  • I answered the original question - why not parsitsya. And the fact that you have some errors on the server (the code, by the way, was added after my answer) is another question, please ask it separately if necessary. - user207618
  • I edited it. Now he is on the topic. The fact is that Kodg is asking a question, then this is from not knowing, in the process it was learned that he WAS off topic. - Maks.Burkov
  • Thanks to all I saw the problem, I will solve it. - Maks.Burkov