javascript - Sending all input fields with jquery .post() -


i have collected values of input field array follows:

 $( ".formbox" ) . each( function(id,elem){     form_fields[ "input-" + $( elem ) . attr( "id" )  ] = $( elem ) . val( );     });   $.log( "collected:", form_fields ); 

this work, , try passing array using post

 $.post(     "server.php",      {         fields: form_fields     },     function(ret) {         if (!ret.success )          alert ( "error! reload please!" );        else        {        }     },      'json'   ); 

however while retrieving, firebug indicates fields empty

as understood need serialize array or not use @ all. use instead?

please tell doing wrong?

---------- added ---------- ...i found this

 form_fields = {}; 

:)

i don't understand how solved problem please tell me difference between array , {}? {} in js ?

{} used creating objects , [] used arrays indicate indexes. difference that.

sample code:

var obj = {name:"captain",last_name:"caveman",run:function(speed){//run;}}  //equivalent   var obj = new object(); obj.name = "captain"; obj.last_name = "caveman"; obj.run = function(speed){   //run; } 

i've created new object on-the-fly {} follow code below call members

document.write(obj.name);  document.write(obj.run("fast")); 

but arrays more simple object.

json: javascript object notation

more json: http://www.w3schools.com/js/js_objects.asp

more arrays: http://www.w3schools.com/js/js_obj_array.asp


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -