The front-end ajax
$(" # aform "). Submit (function () {
The console. The log (" cao a "); The console. The log (" cao a "); The console. The log (" cao a ");
Let associationName=$(" input [name='associationName'] "). The val ();
Let associationStudentNumber=$(" input [name='associationStudentNumber'] "). The val ();
Let associationContent=$(" input [name='associationContent'] "). The val ();
Let associationIcon=$(" input [name='associationIcon'] "). The val ();
The console. The log (associationName);
The console. The log (associationStudentNumber);
$. Ajax ({
Url: "/youshe/association/save",
Type: "post",
DataType: 'text',
ReturnAll: true,
Data: {
"AssociationName" : associationName,
"AssociationStudentNumber" : associationStudentNumber,
"AssociationContent" : associationContent,
"AssociationIcon" : associationIcon,
},
Success: the function (result) {
The console. The log (JSON. Stringify (result));
If (result=="wrong") {
The console. The log (" student id error log ", result);
Alert (result);
} else {
The console. The log (" student id correctly log ", result);
Alert (result);
Window. The parent. The location. The href="https://bbs.csdn.net/youshe/association/index";
}
},
Error: function (err) {
The console. The log (JSON. Stringify (err));
}
});
})
Background the controller
@ PostMapping ("/association/save ")
@ ResponseBody
Public String save (@ RequestParam (value="https://bbs.csdn.net/topics/associationName", the required=false) String associationName,
@ RequestParam (value="https://bbs.csdn.net/topics/associationStudentNumber", the required=false) String associationStudentNumber,
@ RequestParam (value="https://bbs.csdn.net/topics/associationContent", the required=false) String associationContent,
@ RequestParam (value="https://bbs.csdn.net/topics/associationIcon", the required=false) String associationIcon,
HttpServletResponse response) {
SimpleDateFormat formatter=new SimpleDateFormat (" yyyy - MM - dd HH: MM: ss ");
The Date the Date=new Date (System. CurrentTimeMillis ());
Student Student=studentRepository. FindByStudentNumber (associationStudentNumber);
//System. Out. Println (student).
System. The out. Println (formatter. The format (date));
If (student!=null)
{
Association Association=new Association ();
Association. Elegantly-named setName (associationName);
Association. SetStudent (student);
Association. SetContent (associationContent);
Association. SetAssociationIcon (associationIcon);
Association. SetCreateTime (formatter. The format (date));
AssociationRepository. Save (association);
System. The out. Println (" query to student id ");
Return "success1";
}
The else {
System. The out. Println (" query less than student id ");
Return "wrong";
}
}
[code=Java]
CodePudding user response:
Window. The parent. The location href this line commented out and see,May be not waiting for you to point to confirm, page jump,