krx krx - 5 months ago 9
Ajax Question

Passing JavaScript Array To PHP Through JQuery $.ajax

I want to manipulate a javascript array in PHP. Is it possible to do something like this?

$.ajax({
type: "POST",
url: "tourFinderFunctions.php",
data: "activitiesArray="+activities,
success: function() {
$("#lengthQuestion").fadeOut('slow');
}
});


Activities is a single dimensional array like:

var activities = ['Location Zero', 'Location One', 'Location Two'];


The script does not complete when I try this.. Any Ideas or reading materials that will help me accomplish this?

Answer
   data: { activitiesArray : activities },

that's it! now you can access it in PHP:

   <? $myArray = $_REQUEST['activitiesArray']; ?>
Comments