简体   繁体   English

在jQuery Ajax中发送表单数据

[英]Send a form data in jquery ajax

Please help. 请帮忙。 I am trying to send a form data( in temp) using jQuery ajax. 我正在尝试使用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. 我不确定如何在temp变量中过temp表单数据。 Even data:(#form).serialize() doesn't help. 甚至data:(#form).serialize()也无济于事。 I get java.io.IOException: Content type is not multipart/form-data in that case. 我得到java.io.IOException: Content type is not multipart/form-data在这种情况下, java.io.IOException: Content type is not multipart/form-data

Please suggest an idea. 请提出一个想法。 Thanks in advance. 提前致谢。

尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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