1

I am using and have two arrays that I would like to post to a server to be processed and sent in a confirmation email. Any thoughts on the how to properly submit these arrays?

Here are the two arrays:

var array1 = vm.contacts;
var array2 = vm.projects;

$http service:

data = array1; // Is it possible to add array2 here too?

$http.post('http://localhost:9000/api/emails', data)
  .then(function(response) {
      console.log(response);

    }, function(response) {
      console.log('error', response);
    }
2
  • 1
    Why are you not creating an array of these two arrays and sending it ? Commented Oct 3, 2015 at 4:31
  • @Luke P. Issac I'm grabbing two separate arrays from a Firebase database. I'm not really sure how to create an array of these two arrays. I suppose that's part of the problem. Commented Oct 3, 2015 at 4:57

1 Answer 1

3

You could send an object that contains those arrays. Something like this:

var vm = {};
vm.contacts = []; // Array of contacts.
vm.projects = []; // Array of projects.
var data = vm; // Object with arrays.

In your $http service:

$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}

Updated:

By this way you might to send arrays of arrays. Something like this:

var vm = {};
vm.contacts = [];
vm.projects = [];

var arrays = [];
var array1 = vm.contacts;
var array2 = vm.projects;

arrays.push(array1, array2);
console.log(arrays);
var data = arrays;

Then:

In your $http service:

$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}
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.