php - serialize is causing a mess when it comes to gather information? -
since learning on how use serialize, facing hiccup after used below code jquery post
jquery.post("d_in.php",jquery("#myform").serialize(), function(data){ alert("data loaded: " + data); and let's have 2 inputs names small$item_id, each input name follows items itself,
whenever try
echo $_post['small'.$item_id] both in 1
let's 1 small102-s , 3 small1055-a
when print result follows : 13
even when comes more items
how can split number?
update #1:
i tried using explode("&", $_post['small'.$item_id] getting null, seems data sent without & sent without split.
update#2: here whats in d_in.php
foreach ($cart->get_contents() $item) { $item_id = $item['id']; $item_name = $item['name']; $item_price = $item['price']; $item_qty = $item['qty']; $item_ids = explode("-",$item_id); for($i = 0; $i < count($item_ids); $i++){ $item_idn = join("",$item_ids); } echo $_post['small'.$item_idn]; $item_idn = ""; }
working fine me
<form id="test" method="post"> <input type="text" name="small102-s" id="small102-s" /> <input type="text" name="small1055-a" id="small1055-a" /> <input id="testbtn" type="button" /> </form> $(document).ready(function() { $("#testbtn").click(function() { var dataval=$("#test").serialize(); alert(dataval); $.post("1.php",dataval, function(data) { alert("data loaded: " + data); }); }); });
on 1.php
<?php echo $_post['small102-s']; ?> check live here
Comments
Post a Comment