Before I forget – Sending POST variables using jQuery

Written by James McDonald

April 5, 2011

You can pass in POST variables as follows with key=value pairs thusly:

$.ajax({ 
   type: "POST", 
   url: "some.php", 
   data: "name=John&location=Boston", 
   success: function(msg){ 
     alert( "Data Saved: " + msg ); 
   } 
 });

or using an object

var ref_num_url = "http://yourserver/cgi-bin/refnum.pl"; 	
	
$.ajax ({
	url: ref_num_url,
	type: "POST",
	data: { "environment": 'TEST', "blah": "foo"},
	dataType: "xml",
	success: function(myxml){
                      // this says using the returned xml find the
                      // refnum element and give me the text in it
                      // e.g 1234567 returns 1234567
	         alert($( myxml, "refnum").text());
	} 

}); // end ajax

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…