0

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.

1
  • I don't see the point in your loop as you are not using i anywhere - it just seems to do the same thing noOfPage times Commented May 12, 2017 at 10:43

1 Answer 1

1

Try this

<form id="data" method="post" enctype="multipart/form-data">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.