简体   繁体   中英

Send a form data in jquery ajax

Please help. I am trying to send a form data( in temp) using jQuery ajax.

My code:

function post1(URL, PARAMS) {
  var temp = document.createElement("form");
  temp.setAttribute("id", "form");
  temp.action = URL;
  temp.method = "POST";
  temp.encoding = "multipart/form-data";
  temp.style.display = "none";
  <%for(int i=0;i<noOfPage;i++){%>
      for(var x in PARAMS) {
          var opt=document.createElement("textarea");
          opt.name=x;
          opt.value=PARAMS[x];
          temp.appendChild(opt);
      }
  <%}%>

  document.body.appendChild(temp);

  $.ajax({
     type: "POST",
     url: URL,
     async:false,
     cache: false,
     processData:false,
     contentType: false, 
     data: temp, 
     success: function(data){
         alert(data); 
         disablePdfIcon();
     }
   });
}

I am not sure, how to POST the form data in temp variable. Even data:(#form).serialize() doesn't help. I get java.io.IOException: Content type is not multipart/form-data in that case.

Please suggest an idea. Thanks in advance.

尝试这个

<form id="data" method="post" enctype="multipart/form-data">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM