I am trying to explode an array into individual variables which I can then post to my PHP file using $.ajax.
My array is as follows:
var arr = ["11th", "february", "2013"] // How can I go through this array and take each element and place it into its individual variable?
Lightness Races in Orbit
387k77 gold badges673 silver badges1.1k bronze badges
asked Feb 11, 2013 at 0:04
Daniel Makinbo
591 silver badge8 bronze badges
1 Answer 1
You can directly use your array for posting data
when you do your post in ajax, you can send different var and so, send separately arr[0], arr[1] and arr[2]. You can do this by writting this in the configuration of your ajax post:
$.ajax({
..your config..,
data: {
day: arr[0],
month: arr[1],
year: arr[2]
},
...your config...
});
Sign up to request clarification or add additional context in comments.
Comments
lang-js
day,month,year. I know its odd to do this but I have no other option. Thanks....,data { day: arr[0], month: arr[1], year: arr[2] }...