undefined在警告框jquery ajax中返回

The following code resides in my php file (cl.php):

<?php for( $i = 0; $i < count( $getClFormData->data ); $i++ ) :?>
<tr>
    <input type='hidden' name='itemid[]' value='<?php echo $getClFormData->data[$i]['c_item_id'] ?>'>
    <td><?php echo $getClFormData->data[$i]['item'] ?></td>
    <td><?php echo $getClFormData->data[$i]['description'] ?></td>
    <td><?php echo $getClFormData->data[$i]['norm'] ?></td>
    <td>
        <input type='radio' name='kforce_mont1_<?php echo $i ?>' value='1' class='bobtailradiook'>OK<br/>
        <input type='radio' name='kforce_mont1_<?php echo $i ?>' value='0' class='bobtailradionok' alt='<?php echo $getClFormData->data[$i]['c_item_id'] ?>'>NOK
    </td>
</tr>
<?php endfor;

where <input type='radio' name='kforce_mont1_<?php echo $i ?>' value='0' class='bobtailradionok' alt='<?php echo $getClFormData->data[$i]['c_item_id'] ?>'>NOK is relevant to my question.

Further down cl.php, the following code:

if(isset($_POST['itemid'])){
    <input type='hidden' class='test' value='<?php echo $_POST['itemid']; ?>'>
}

JS Code

$( document ).ready(function() {
    $('.bobtailradionok').each(function() {
        $( this ).click(function() {
            //$("#errortable").show();
            //alert($(this).attr('alt'));
            $.ajax({
                type: 'POST',
                data: {itemid: $(this).attr('alt')},
                url: "cl.php",
                success:function(data){
                    alert($('.test').val());
                    console.log(data);
                }
            });
        });
    });
});

The jquery above returns 'undefined' in the alertbox, while I want it to return the itemid. Why is 'undefined' returned? Since, <input type='hidden' class='test' value='<?php echo $_POST['itemid']; ?>'> is correctly returned as <input type='hidden' class='test' value='1'> or <input type='hidden' class='test' value='2'> depending on the box clicked, when I look in the console.log.

Where do you ever add the AJAX response to the page?

This is showing you what's in the response:

console.log(data)

But this is looking for a class="test" element on the page:

$('.test').val()

Did you mean to add the response to the page somewhere first? For example:

$('#someElement').append(data);
alert($('.test').val());

Or perhaps specifically look in the response for the value?:

$('.test', data).val()

or:

$(data).find('.test').val()

Basically you're just looking for your class="test" element in the wrong place.