Otherwise when I post my data with $.ajax
it works perfectly
$.ajax({
url: 'CreateProduct',
data: formData,
processData: false,
contentType: false,
type: 'POST'
});
Is it any opportunity to use $.post
instead of $.ajax
? Am I miss something??
CodePudding user response:
It seems that you may encounter jQuery adding a content type header, which will cause the boundary string to be lost.
You must set the contentType option to false to force jQuery not to add a Content-Type header for you, otherwise, the boundary string will be lost. In addition, you must set the processData flag to false, otherwise, jQuery will try to convert your FormData to a string, which will fail.
And we set the contentType to false in ajax to prevent JQuery from operating on it, thereby losing the delimiter and making the server unable to parse the file normally.
Like you changed:
$.ajax({
url: 'CreateProduct',
data: formData,
processData: false,
contentType: false,
type: 'POST'
});
CodePudding user response:
I tried to change it in this way and it works
$.post({
url: 'Submit',
data: formData,
processData: false,
contentType: false
});
Is there any suggestions how I can improve it?