The parameters passed by ajax to the backend include both files and ordinary data

in a form form at the front desk

<form class="form-horizontal">
  <div class="form-group">
    <label for="imgurl" class="col-sm-2 control-label">:</label>
     <div class="col-sm-8">
        <input type="file" id="imgurl" style="float: left;">
    </div>
 </div>
<div class="form-group">
    <label for="showimg" class="col-sm-2 control-label"></label>
    <div class="col-sm-8">
        <div class="previewBox">
              <img id="showimg" style="width: 250px;height: 170px;">
        </div>      
        <br><br>
        <a class="btn btn-info cropBtn"></a>
    </div>
</div>
<div class="form-group">
    <label for="title" class="col-sm-2 control-label">:</label>
    <div class="col-sm-8">
       <input type="text" class="form-control" id="title" value=" 
        <%=articleData.title%>">
  </div>
</div></form>

the data sent to the background includes both files (pictures) and plain text data. How should entype be set? do you want to set one point? How should I pass the data in $.ajax ()? How does the backstage (node) accept it? What"s the general idea.

Mar.09,2021

put all the data in FormData and search for "ajax file upload".


https://codeshelper.com/a/11.

Menu