Home > Back-end >  The use of formdata record code
The use of formdata record code

Time:02-04

Through the video to learn the formdata before, but when you use problems,

The front end

$(' # submit). Click (function () {
Var book={};
The book. The name=$(' # name). Val ();
The book. The author=$(' # author). Val ();
The book. The category={
Id: $(' # category). Find (' option). Not (the function () {
return ! This. Selected;
}). Data (' id ')
};
Var formData=https://bbs.csdn.net/topics/new formData ();
FormData. Append (' book 'JSON. Stringify (book));
$. Ajax ({
Url: '/happens',
Type: "POST",
Data: formData,
ContentType: false,
ProcessData: false,
Cache: false,
Success: the function (data) {
If (data. Success) {
Alert (' submitted to success! ');
} else {
Alert (' request failure);
}
}
});

The new out a formdata object, and append a String String the book

Problem on the back-end when I was using a request. The getParameter (" book ") found in the name of the value doesn't write wrong don't get the book under the condition of the string

Turns out that the initial formdata is refer to related information does not support using request access to, want to use to get into the content must rely on the relevant jar and configuration

Pox files need to introduce common - fileupload


Commons - fileupload
Commons - fileupload
. ${Commons fileupload - version} & lt;/version>


Spring's configuration file needs the following configuration

& gt;





One

Above is the application of formdata
  • Related