0

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?
6
  • What does the resulting object look like? Commented Feb 11, 2013 at 0:06
  • You ca directly used your array for posting data. What is the purpose of doing this ? WHat should be the name of each var ? Commented Feb 11, 2013 at 0:11
  • I would like to separate the array into individual variables so that I don't have to do it on the server side when I use the values to query a table. Variables are called, day, month, year. I know its odd to do this but I have no other option. Thanks. Commented Feb 11, 2013 at 0:14
  • Yes but when you will do your post in ajax, you can send different var and so, send separatelly arr[0], arr[1] and arr[2]. You can do this by writting this in the configuration of your ajax post: ...,data { day: arr[0], month: arr[1], year: arr[2] }... Commented Feb 11, 2013 at 0:29
  • @user1073122 Wow thats great, I did not know that was possible. I have honestly tried to research that exact functionality online and could not find any information on it. Thanks again, I am going to give it a try! Commented Feb 11, 2013 at 0:31

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.