Send Extra Data with Ajax Get or Post Request


If you want to send some extra data (key/values) to the server while submitting an HTML form using jQuery Ajax function then its can be achieved by appending your query string data parameter,

Code Snippet
$.ajax({
  url: "../server-url.php",
  type: "POST",
  async: true, 
  cache: false,
  data: $('form').serialize() + "&key1="+ value1 + "&key2=" + 
          document.getElementById("field").value,
  success : function(val){
  alert("Success!");   
  }
});

After $('form').serialize() I have just appended the data as query String.



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap