tags:

views:

29

answers:

1

Hey all

since I am learning on how to use serialize, I am facing a hiccup where after I used the below code which is the Jquery post

jQuery.post("d_in.php",jQuery("#myform").serialize(), function(data){
   alert("Data Loaded: " + data); 

and let's say I have 2 inputs which names are Small$item_id, where each input name follows the items itself,

whenever I try

echo $_POST['Small'.$item_id] I get both in one

let's say 1 for small102-s and 3 for small1055-a

when I print the result I get as follows : 13

even when it comes to more items

how can I split the number?

Update #1:

i tried using explode("&", $_POST['Small'.$item_id] i am getting null, it seems the data is sent without the & it is sent together without any split.

Update#2: here is whats in d_in.php

foreach ($cart->get_contents() as $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 = "";
        }
A: 

Working fine for 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 the 1.php

<?php echo $_POST['small102-s']; ?>

Check Live Here

vinothkumar
i have updated the question please see what i used in d_in.php and btw when it comes to gather the information i am using a foreach loop that gets me the ids of the items which are in the cart allowing me to get everything what i am sending through ajax
Mahmoud