how to send multiple values using ajax in javascript?

how to send multiple values using ajax in javascript? – Data can be sent through JSON or via normal POST. We are sending an ajax request to a php server side file as shown here:

how to send multiple values using ajax in javascript?

The simple Example is:

data: {is_active: true, product: name},

how to send multiple data with $.ajax() jquery?

You can make an object of key/value pairs as well as jQuery will do the rest for you:

$.ajax({
    ...
    data : { is_active : 'bar', status : 'is_active' },
    ...
});

Send multiple data with ajax in PHP

Data can be sent through JSON or via normal POST. Following is an example showing data sent through JSON βˆ’

var is_active = 1;
var status = 2;
var product = 3;
$.ajax({
   type: "POST",
   contentType: "application/json; charset=utf-8",
   url: "your_url_goes_here",
   data: { data_1: is_active, data_2: status, data_3: product },
   success: function (result) {
      // perform operations here
   }
});

With normal post, the below code can be used βˆ’

Also Read This πŸ‘‰   jquery remove last comma from string Example

$.ajax({
   type: "POST",
   url: $('form').attr("action"),
   data: $('#form0').serialize(),
   success: function (result) {
      // perform operations here
   }
});

An alternate to the above code has been demonstrated below βˆ’

data:'id='+ID & 'member_code=' + MEMBERCODE,
with:
data: {id:ID, member_code:MEMBERCODE}
so your code will look like this :
$(document).ready(function(){
   $(document).on('click','.show_more',function(){
      var ID = 10;
      var MEMBERCODE =1;
      $('.show_more').hide();
      $('.loding').show();
      $.ajax({
         type:'POST',
         url:'/loadData.php',
         data: {id:ID, member_code:MEMBERCODE},
         success:function(html){
            $('#result_name'+ID).remove();
            $('.post_list').append(html);
         }
      });
   });
});

Free Live Chat for Any Issue

send multiple data using ajax

here simple Example, you will learn to ajax send multiple data to php

Also Read This πŸ‘‰   jQuery Enable Disable Submit Button Example

index.html

$.ajax({
	url: "/pakainfo_api",
    type: "GET",
    data: {p1: "value1", p2: "value2"}, // multiple data we want to send
    success: function(data){ 
   		console.log(data);
    }
}).done(function(){
    console.log("Success.");
}).fail(function(){
    console.log("An error has occurred.");
}).always(function(){
  	console.log("Complete.");
});

Don’t Miss : How To Multiple Urls In One Ajax Call?

Example : 1 how to send multiple array in ajax?

$.ajax({
	url: "/pakainfo_api",
    type: "GET",
    data: {p1: ["v1", "v2"], p2: ["v1", "v2"]}, // multiple array we want to send
    success: function(data){ 
   		console.log(data);
    }
}).done(function(){
    console.log("Success.");
}).fail(function(){
    console.log("An error has occurred.");
}).always(function(){
  	console.log("Complete.");
});

We hope it can help you…