narjis Posted January 31, 2012 Share Posted January 31, 2012 I want to pass an json array by using javascript and then pass to a php script. Hewre's my script <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Random Box changing colors</title> <script type="text/javascript" language="javascript"> function ToggleBackgrnd(){ /* this function checks the length of each character in input block_*/ var jsonObj = []; var x; /*for (x=0;x<8;x++){ num[x] = array.push(document.getElementById("block_"+ x)); for (var i = 0; i < 5; i++) { x =document.getElementById("block_"+ i); jsonObj.push({i: x}); } //console.log(jsonObj); $.post("randomEg.php",jsonObj,function(data){ alert(data);}); } </script> </head> <body> <form method="post" action=""> <p>Enter Password </p> <table width="200" border="0" align="center"> <tr> <td width="12"><label for="block_1"></label> <input name="block_1" type="password" id="block_1" size="1" maxlength="1" /></td> <td width="12"><input name="block_2" type="password" id="block_2" size="1" maxlength="1" /></td> <td width="12"><input name="block_3" type="password" id="block_3" size="1" maxlength="1" /></td> <td width="12"><input name="block_4" type="password" id="block_4" size="1" maxlength="1" /></td> <td width="12"><input name="block_5" type="password" id="block_5" size="1" maxlength="1" /></td> <td width="12"><input name="block_6" type="password" id="block_6" size="1" maxlength="1" /></td> <td width="12"><input name="block_7" type="password" id="block_7" size="1" maxlength="1" /></td> <td width="12"><input name="block_8" type="password" id="block_8" size="1" maxlength="1" /></td> </tr> </table> <p> <input type="submit" name="submit" value="Post" onclick="ToggleBackgrnd();" /> </p> </form> </body> </html>[code] Quote Link to comment Share on other sites More sharing options...
trq Posted January 31, 2012 Share Posted January 31, 2012 And your question/problem is? Quote Link to comment Share on other sites More sharing options...
narjis Posted February 2, 2012 Author Share Posted February 2, 2012 I am unable to do so please check my script if I have done something wrong. Thankyou Quote Link to comment Share on other sites More sharing options...
scootstah Posted February 2, 2012 Share Posted February 2, 2012 Any errors? What does print_r($_POST); look like? Quote Link to comment Share on other sites More sharing options...
goodacre.liam Posted February 5, 2012 Share Posted February 5, 2012 Is it because the majority of your code is actually commented out from the beginning of this line: /*for (x=0;x<8;x++){ Quote Link to comment Share on other sites More sharing options...
narjis Posted February 5, 2012 Author Share Posted February 5, 2012 I've uncommented it now here my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Random Box changing colors</title> </head> <body> <form method="post" action=""> <p>Enter Password </p> <table width="200" border="0" align="center"> <tr> <td width="12"><label for="block_1"></label> <input name="block_1" type="password" id="block_1" size="1" maxlength="1" /></td> <td width="12"><input name="block_2" type="password" id="block_2" size="1" maxlength="1" /></td> <td width="12"><input name="block_3" type="password" id="block_3" size="1" maxlength="1" /></td> <td width="12"><input name="block_4" type="password" id="block_4" size="1" maxlength="1" /></td> <td width="12"><input name="block_5" type="password" id="block_5" size="1" maxlength="1" /></td> <td width="12"><input name="block_6" type="password" id="block_6" size="1" maxlength="1" /></td> <td width="12"><input name="block_7" type="password" id="block_7" size="1" maxlength="1" /></td> <td width="12"><input name="block_8" type="password" id="block_8" size="1" maxlength="1" /></td> </tr> </table> <p> <input type="submit" name="submit" value="Post" onclick="ToggleBackgrnd();" /> </p> </form> <script type="text/javascript" language="javascript" src="jquery-1.6.1.min.js"></script> <script type="text/javascript" language="javascript"> function ToggleBackgrnd(){ /* this function checks the length of each character in input block_*/ var jsonObj = []; var x; var y; for (var i = 1; i < 6; i++) { y="block_"+ i; x =document.getElementById(y).value; jsonObj.push({i: x}); //document.write(x); } // console.log(jsonObj); $.post("randomArreg.php",jsonObj,function(data){ alert("success"); }); } </script> </body> </html> Now the console is printing the result but some how it is not showing print_r($_POST['jsonObj']) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.