I am using nodejs with expressjs. I am making an ajax call that queries a job table for multiple jobs and also each job's corresponding Customer table. Individually I get two arrays' of objects. I populate the second array by iterating through the selected jobs' Customer ID like.
for(var i=0; i<jobs.length; i++) {
for(j=0; j<customerList.length; j++) {
if (customerList[j].ID == jobs[i].CustomerID) {
customerRecords.push(customerList[j]);
}
}
What I am left with is two arrays of objects - 1. jobs 2. customerRecords. I have tried in many different forms to return these two objects to my view with as many variations of res.send(object/objects) that I could think of with no success. After googling, from what I read by a similar post I can only return one object with my ajax call? Is this true? how do I return both of these arrays of objects to my view?
-on standby, thank you for any help.
You simply put them both in another object. Either:
{
"array1" : [1,2],
"array2" : [3,4]
}
or
[
[1,2],
[3,4]
]
After googling, from what I read by a similar post I can only return one object with my ajax call? Is this true? how do I return both of these arrays of objects to my view?
Yes and no. Of course, you could only have one result. But you could add both:
{
customerList:[],
jobs:[]
}
So in effect: two arrays in one object.
After you got the data: result.customerList (assuming you saved the outcome in an object named »result«) gives you the customerlist (as expected).