javascript - how to Pass array variable in PHP POST? -


would ask if possible/how pass array variable in php using javascript

i have following code

jquery("#save").click(function() {       var val = [];     jquery('#themes:checked').each(function(i){       val[i] = jquery(this).val();     });        jquery("#status").load("<?=$config['publicdomain']?>/saveprofile.php?wthemes="+val);   }); 

this form field

<span>     <input id="themes" name="themes" type="checkbox" value="theme a">     <input id="themes" name="themes" type="checkbox" value="theme b"> </span> 

your input should be

<input type="hidden" id="car" name="vehicle[]" value="car" /> <input type="hidden" id="bike" name="vehicle[]" value="bike" /> <input type="hidden" id="truck" name="vehicle[]" value="truck" /> <input type="hidden" id="cycle" name="vehicle[]" value="cycle" /> <input type="hidden" id="train" name="vehicle[]" value="train" /> 

then in server side

<?php  $vehicles=$_post["vehicle"];  foreach($vehicles $vehicle){  // sfuff here }  ?> 

if using ajax may you

$.ajax({     url: "index.php",     type: 'post',     data: form_data,     datatype:"json",     success: function(data) {         alert(data[0]);    } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -