angularjs - Angular Diference between $scope.arrays and javascript pure array on posting nested objs -


im new angular seems me angular bind new stuff in arrays created , used in controller scope, in way cant send nested array through http post.

the problem happens when trying send or without header, using $.param serialize or not.

 $http({         url: '../routines.php?action=salvarpesquisa',         method: "post",         data: $.param($scope.pesquisa),         headers:{'content-type': 'application/x-www-form-urlencoded; charset=utf-8'}     }); 

on console.log($scope.pesquisa) have: console.log($scope.pesquisa)

using that, post end without form data. break head trying figure out on headers {undefined, json, form-uyrlencoded etc}, trying fetch json using file_get_contents('php://input') on php when changing headers , on. solution came when used simple javascript object on same code, rebuilding object. lame, worked:

        var outro = {id:pesquisa.id,titulo:pesquisa.titulo,descricao:pesquisa.descricao,arrperguntas:pesquisa.arrperguntas,arrexcluirperguntas:pesquisa.arrexcluirperguntas};         for(var x in outro.arrperguntas){             outro.arrperguntas[x].arrexcluiropcoes = pesquisa.arrperguntas[x].arrexcluiropcoes;             outro.arrperguntas[x].arropcoes = pesquisa.arrperguntas[x].arropcoes;         }         return $http({             url: '../routines.php?action=salvarpesquisa',             method: "post",             data: $.param(outro),             headers:{'content-type': 'application/x-www-form-urlencoded; charset=utf-8'}         }); 

finaly question. why!??!?!?!?!??!

using that, post on php came result structure:

array (     [id] =>      [titulo] => title unique     [descricao] => description unique     [arrperguntas] => array         (             [0] => array                 (                     [id] => novo0                     [pergunta] => question 1                     [tipo] => 2                     [variacao] => 0                 )              [1] => array                 (                     [id] => novo1                     [pergunta] => multiple choice question 2                     [tipo] => 1                     [arropcoes] => array                         (                             [0] => array                                 (                                     [id] => novo0                                     [opcao] => opt1 q2                                 )                              [1] => array                                 (                                     [id] => novo1                                     [opcao] => opt2 q2                                 )                              [2] => array                                 (                                     [id] => novo2                                     [opcao] => opt3 q2                                 )                          )                      [variacao] => 2                 )              [2] => array                 (                     [id] => novo2                     [pergunta] => simple option question 3                     [tipo] => 1                     [arropcoes] => array                         (                             [0] => array                                 (                                     [id] => novo0                                     [opcao] => opt 1 q3                                 )                              [1] => array                                 (                                     [id] => novo1                                     [opcao] => opt2 q3                                 )                          )                      [variacao] => 1                 )          )  ) 


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -