js code, the two alert can pop up right
function addCourse () {
//accept the front-end data (with the original js)
Var data=https://bbs.csdn.net/topics/new FormData (document. GetElementById (" addcourse_form "));
Var name=$(" # addcourse_form input: eq (0) "). The val ();
Var order=$(" # addcourse_form input: eq (1) "). The val ();
Var picture=$(" # addcourse_form input: eq. (2) "). The val ();
Var desc=$(" # addcourse_form textarea "). The val ();
Alert (name + "" + order + +" "+" "+ picture desc);
Alert (data. The get (" name ") + "" + data. The get (" picture") + "" + data. The get (" order") + "" + data. The get (" desc"));
//send ajax asynchronous request
$. Ajax ({
Url: basePath + "course/addCourse",
Type: "post",
ProcessData: false,
ContentType: false,
Data: {
"Name" : name,
"Order" : order,
"Picture" : picture,
"Desc" : desc
},
DataType: "json",
Success: the function (result) {
If (result. The status==1) {
Alert (result. The message);
} else if (result. The status==0) {
Alert (" add course failure!!!!! ");
}
},
Error: function () {
Alert (" attempt failed!!!!! ");
}
});
return false;
}
back-end Controller code
@ RequestMapping (value="https://bbs.csdn.net/topics/addCourse", method=RequestMethod. POST)
@ ResponseBody
Public Result addCourse (
Course Course,
String courseId,
MultipartFile addFile,
It request,
HttpServletResponse response) {
Result the Result=null;
Result=this. CourseService. AddCourse (course, courseId, addFile, request, response);
return result;
}
Course entity class code, there is a setter and getter method
private String id;
private String name;
Private String picture;
Private Integer order;
Private String desc;
CodePudding user response:
In the Course before the Course add @ RequestBody
@ RequestMapping (value="https://bbs.csdn.net/topics/addCourse", method=RequestMethod. POST)
@ ResponseBody
Public Result addCourse (
@ RequestBody Course Course,
String courseId,
MultipartFile addFile,
It request,
HttpServletResponse response) {
Result the Result=null;
Result=this. CourseService. AddCourse (course, courseId, addFile, request, response);
return result;
}
CodePudding user response:
BasePath + "course/addCourse", the link address: are you sure is right??????? CodePudding user response: