FileTransfer : POST params with array Key -> value


#1

Hi,

I would like to use FileTransfer to transfert a file with POST params. if i wirte

var params = {};
params.value1 = 'test';
...

It’s work fine, but when i write :

var params {arrayValue : ''};
params.arrayValue = {value1: 'test', value2: 'test'};

It does’nt work. I can’t access to arrayValue…

Can you help me ?

Thank You


#2

do you mean:

var params = {
  arrayValue: ''
};

btw {} = Object and [] = Array implicit an array is also an object… but to be clear Object = {key: value}, Array = [value, value2]


#3

Yeah but i would like an array with key / value and this value is an another array key / value.

Thank you very much


#4

you have to set something like that:

var params {
  myArrayParam: ['1', '2', '3']
};
// console.log(params.myArrayParams[0]);

#5

Thank you

It’s not possible to make something like this ?
var params = {
data : {
title : ‘test’
}
};


#6

yeah but than it is not an array :wink: it is an object:

var params = {
  firstName: 'Hans',
  lastName: 'Wurst'
}

#7

Thank you ^^ but it’s another issuer . i’ve a back end in PHP, and when i post my data, i’ve got an Object like this :
var object = { data : { title : ‘value’, categorie: ‘value2’, … }}; when i make an object like this, it doesn’t work …, but whien i make a basic http.post, it’s work.

Thank you for your help


#8

maybe your PHP backend is not configured to handle JSON request body data per default.
AngularJS is sending the data in contentype application/json


#9

I make this :

var params = {};
params.value1 = JSON.stringify({title: 'title'});

And it works fine :slight_smile: thank you very much


#10

I would not make this on clientside. You can simple parse json data in your php-backend