Send Extra Data with Ajax Get or Post Request

Posted on : Mon, 28th Sep 15 01:30 pm UTC
100+ votes

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,

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

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

Code2care's mission is to share varied knowledge in technical and non-technical areas gathered during day-to-day learnings and development activities so that our visitors can leverage this portal to find solutions to their queries without re-inventing the wheel. Technical posts include Learnings, Tutorials, Video Tutorials, Code Snippets, Tips-n-tricks.

Follow us : Facebook - Twitter - Google +