send data in ajax code example

Example 1: ajax data post call in javascript

$.ajax({
   url: 'ajaxfile.php',
   type: 'post',
   data: {name:'yogesh',salary: 35000,email: '[email protected]'},
   success: function(response){

   }
});

Example 2: how to send data using ajax

$.ajax({
	url: "/something", // the url we want to send and get data from
    type: "GET", // type of the data we send (POST/GET)
    data: {p1: "This is our data"}, // the data we want to send
    success: function(data){ // when successfully sent data and returned
    	// do something with the returned data
   		console.log(data);
    }
}).done(function(){
	// this part will run when we send and return successfully
    console.log("Success.");
}).fail(function(){
    // this part will run when an error occurres
    console.log("An error has occurred.");
}).always(function(){
    // this part will always run no matter what
  	console.log("Complete.");
});

Example 3: $.post javascript

//$.post with jQuery

$.post(
  "path/to/your/php/file", 
  {
    param1: "Value",
    param2: "Value"
},
  function(data) {
  //Callback here
  }
);

Tags:

Php Example