Home > front end >  How to use ajax to excel file upload springboot project?
How to use ajax to excel file upload springboot project?

Time:01-26

I was the ajax excel file upload all these two days not in the mood to write you, eventually came to BBS ask front-end bosses,,
This is my form
 


So write directly, without js my backend is you can receive the upload of the file, but also returned to the status code and message, I wrote

But I think when click upload, need to confirm to upload, then upload the results displayed and

Then I want to write a js,

This is js
 
The function upload () {
Layer. Confirm (' sure upload? '{
BTN: [' sure ', 'cancel']
}, function () {
$. Ajax ({
Type: "post",
Url:/require/readExcel,
Data: $(' # file_1) [0]. Files [0],
Success: the function (r) {
If (r.c ode===0) {
Layer. MSG (r.m sg);
ReLoad ();
} else {
Layer. MSG (r.m sg);
}
}
});
})
}

But after I wrote this js, changing the above HTML inside type from sumbit to the button, baidu to find the answer, make entype into the content, the back-end and newspaper. MultipartException: the Current request is not a multipart request,,,,,,,,,,,,,,,

Anyway is up I am tired of learning, it is not successful, yet I'm thinking about how through ajax in js files uploaded to the backend can not quote the Current request is not a multipart request, then can pass layer. MSG () response to the following my backend back to become as a result,,,
Bosses, save the children, and mentality collapse, and front too do,

CodePudding user response:

Sometimes life is such a drama,,,, I haven't solve tm had so long,,, then Posting a BBS above, then click on the blog, a suggested, then tm suddenly became again!!!!!!!!!! I really do, and don't want to talk,,,

CodePudding user response:

I know where is the reason!!!!!!
It all comes from my clever!!!!!!!!!!
Js such written right
 
The function upload () {
Var file=$(" # file_1 ") [0]. Files [0].
Var formData=https://bbs.csdn.net/topics/new formData ();
FormData. Append (" file ", the file).
Layer. Confirm (' sure upload? '{
BTN: [' sure ', 'cancel']
}, function () {
$. Ajax ({
Type: "post",
Url:/require/readExcel,
Data: formData,
ProcessData: false,
ContentType: false,
Success: the function (r) {
If (r.c ode===0) {
Layer. MSG (r.m sg);
//reLoad ();
} else {
Layer. MSG (r.m sg);
}
}
});
})
}

I directly behind the data to assign a value, not used formData, view the formData should be done to form data encapsulation
  •  Tags:  
  • Ajax
  • Related