Pass array to ajax request in $.ajax()

Poonam Bhatt picture Poonam Bhatt · Jan 17, 2012 · Viewed 641.9k times · Source

I want to send an array as an Ajax request:

info[0] = 'hi';
info[1] = 'hello';

$.ajax({
  type: "POST",
  url: "index.php",
  success: function(msg){
    $('.answer').html(msg);
  }
});

How can I do this?

Answer

Diode picture Diode · Jan 17, 2012
info = [];
info[0] = 'hi';
info[1] = 'hello';


$.ajax({
   type: "POST",
   data: {info:info},
   url: "index.php",
   success: function(msg){
     $('.answer').html(msg);
   }
});