javascript - Create a JSON Array from dynamic values in jquery -


i need create array {"groupslist":{"groupname":["user1","user2","user3"],"groupname2":["user1","user2","user3"],"groupname3":["user1","user2","user3"]}} values different ajax call server, in first ajax call grouplists groupname, groupname2 etc , in success function make ajax call each groupname , user particular groupname , create array , push main grouplist, output getting not correct think have use callbacks make correct, please me , tell me `

$.ajax({     url: 'get_group_list',     type: 'post',     success: function (data) {         groupnamess=data.replace("[","").replace(/"/g, "").replace("]","").split(',');         console.log("groupnameeeee",groupnamess);     for(var in groupnamess)     {      grup[i]=groupnamess[i];      userss.push({             label:groupnamess[i],             value:groupnamess[i]           });     grupss.push(groupnamess[i]);     }     for(var in grupss)      {         console.log("geeeeeeeeeeeeeeeeeeeeeeeeee",grupss);         console.log("geeeeeeeeeeeeeeeeeeeeeeeeee",groupnamess[i]);          $.ajax({             url: 'get_user_list',             type: 'post',             data:{'name':groupnamess[i]},                success: function (data) {                 console.log("55555555555555555555"+data);                 if(data!='[]')                 {                     //addy.substr(0, addy.indexof('.'));                      var group=groupnamess[i];                     console.log("cccccccccccccccccccccc"+group);                     grouplist[group]=new array();                     console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+data);                     var usrs=data.replace("[","").replace(/"/g, "").replace("]","").split(',');                     for(var j in usrs)                     {                         grouplist[group].push(usrs[j]);                         console.log("rrrrrrrrrrrrrrr"+usrs[j]);                     }                     console.log('ooooooooooooooooooooooooooo', grouplist);                     var grp=$.parsejson(grouplist);                     consoloe.log(grp);                  }             },             error:function(xmlhttprequest, textstatus, errorthrown)             {                 console.log('error', errorthrown);             }         });          console.log("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");     }        users=userss;     console.log("gupppppppppppppppppp"+grupss);     console.log('success', users);     },     error:function(xmlhttprequest, textstatus, errorthrown)     {      console.log('error', errorthrown);     } });` 

output is

 groupnameeeee ["user00", "super user", "supreme user"] myjs.js:35 geeeeeeeeeeeeeeeeeeeeeeeeee ["user00", "super user", "supreme user"] myjs.js:48 geeeeeeeeeeeeeeeeeeeeeeeeee user00 myjs.js:49 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee myjs.js:80 geeeeeeeeeeeeeeeeeeeeeeeeee ["user00", "super user", "supreme user"] myjs.js:48 geeeeeeeeeeeeeeeeeeeeeeeeee super user myjs.js:49 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee myjs.js:80 geeeeeeeeeeeeeeeeeeeeeeeeee ["user00", "super user", "supreme user"] myjs.js:48 geeeeeeeeeeeeeeeeeeeeeeeeee supreme user myjs.js:49 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee myjs.js:80 guppppppppppppppppppuser00,super user,supreme user myjs.js:84 success  [object, object, object]  myjs.js:85 55555555555555555555["sample_vh.com"] myjs.js:55 ccccccccccccccccccccccsupreme user myjs.js:60 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa["sample_vh.com"] myjs.js:62 rrrrrrrrrrrrrrrsample_vh.com myjs.js:67 ooooooooooooooooooooooooooo  object {supreme user: array[1]}  myjs.js:69 uncaught syntaxerror: unexpected token o myjs.js:70 55555555555555555555["veera_tls.com","v_v.com","sample_vh.com"] myjs.js:55 ccccccccccccccccccccccsupreme user myjs.js:60 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa["veera_tls.com","v_v.com","sample_vh.com"] 

myjs.js:62 rrrrrrrrrrrrrrrveera_tls.com myjs.js:67 rrrrrrrrrrrrrrrv_v.com myjs.js:67 rrrrrrrrrrrrrrrsample_vh.com myjs.js:67 ooooooooooooooooooooooooooo object {supreme user: array[3]} myjs.js:69 uncaught syntaxerror: unexpected token o myjs.js:70 55555555555555555555[]

i not able understand code.

just create array , pass array json.stringify jsonify it.

var arr = [1,2,3,4,5]; json.stringify(arr); // "[1,2,3,4,5]" 

Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -

PHPMotion implementation - URL based videos (Hosted on separate location) -