title: Send post data from html FORM with Javascript?
body: <p>I am trying to send post data from from with empty action and send the info with javascript to the file that must handle the post information.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;HTML&gt;
  &lt;head&gt;
  &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
              &lt;script&gt;    
      function post_to_url(path, params, method) {
          method = method || "post";
  
          var form = document.createElement("form");
  
          form._submit_function_ = form.submit;
  
          form.setAttribute("method", method);
          form.setAttribute("action", path);
  
          for(var key in params) {
              var hiddenField = document.createElement("input");
              hiddenField.setAttribute("type", "hidden");
              hiddenField.setAttribute("name", key);
              hiddenField.setAttribute("value", params[key]);
  
              form.appendChild(hiddenField);
          }
  
          document.body.appendChild(form);
          form._submit_function_();
      }
      post_to_url("./postinfo.php", { submit: "submit" } );
          &lt;/script&gt;   
  &lt;form method="post" onsubmit="return post_to_url()"&gt;
  &lt;input type="text" name="ime"&gt;
  &lt;input type="submit" id="submit" name="submit" value="Send"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>So how i can send the post data to <code>postinfo.php</code> with javascript with empty action in my html form?</p>
  
  <p>Thanks in advance!</p>