php - Having issues with dynamic array -
this code generates array , posts backend api. on backend store $_post in $page['body'] , print_r($page) in effort test create sure info i'm sending showing correctly , formatted right. below result. javascript , not friends, pointers/tips fixing array much appreciated.
if in response in [body] index, info beingness passed javascript showing there beingness 'undefined'. i'm not sure causing this.
request
$('#find_carriers').click(function(){ var info = new array(); data.push( { 'general': { 'shipper': $('#shipper_zip').val(), 'consignee': $('#consignee_zip').val(), 'shipment_type': $('#direction').val(), 'total_weight': $('#total_weight').val() } } ); $('#accessorials').find('input:checkbox:checked').each(function(acc_index){ data.push( {'accessorials': {acc_index : $(this).val() } } ); }); $('#units').find('table.unit').each(function(unit_index){ data.push( {'units': { unit_index : { 'num_of': $(this).find('.unit_num_of').text(), 'type': $(this).find('.unit_type').text(), 'weight': $(this).find('.unit_weight').text() } } } ); $(this).find('tbody.products tr').each(function(product_index){ data.push( {'products': { product_index : { 'pieces': $(this).find('td.pieces').text(), 'weight': $(this).find('td.weight').text(), 'class': $(this).find('td.class').text() } } } ); }); }); $.post('index.php?p=api&r=text&c=ctsi&m=lcc', data, function(resp){ alert(resp); }); homecoming false; });
response
array ( [user] => array ( [id] => 33 [name] => user [authenticated] => 1 [level] => user ) [title] => [body] => array ( [undefined] => ) [message] => array ( )
)
php
public function lcc($data) { global $page; if($page['user']['level'] != "user") { $this->errorstate = 1; $this->errormessage = "access denied."; homecoming false; } $page['body'] = $_post; }
php handles dumping
case 'text': print_r($page); break;
changing javascript next works:
$('#find_carriers').click(function(){ var info = new object(); data.general = { 'shipper': $('#shipper_zip').val(), 'consignee': $('#consignee_zip').val(), 'shipment_type': $('#direction').val(), 'total_weight': $('#total_weight').text() }; data.accessorials = []; $('#accessorials').find('input:checkbox:checked').each(function(acc_index){ data.accessorials.push($(this).val()); }); alert('hello') data.units = []; data.products = []; $('#units').find('table.unit').each(function(unit_index){ data.units.push({ 'num_of': $(this).find('.unit_num_of').text(), 'type': $(this).find('.unit_type').text(), 'weight': $(this).find('.unit_weight').text() }); $(this).find('tbody.products tr').each(function(product_index){ data.products.push({ 'pieces': $(this).find('td.pieces').text(), 'weight': $(this).find('td.weight').text(), 'class': $(this).find('td.class').text() }); }); }); $.post('index.php?p=api&r=text&c=ctsi&m=lcc', data, function(resp){ alert(resp); }); homecoming false; });
result
array ( [user] => array ( [id] => 33 [name] => user [authenticated] => 1 [level] => user ) [title] => [body] => array ( [general] => array ( [shipper] => [consignee] => [shipment_type] => outbound/prepaid [total_weight] => 2 ) [accessorials] => array ( [0] => 17 [1] => 19 ) [units] => array ( [0] => array ( [num_of] => 1 [type] => bobs [weight] => 1 ) [1] => array ( [num_of] => 1 [type] => bobs [weight] => 1 ) ) [products] => array ( [0] => array ( [pieces] => 1 [weight] => 1 [class] => ) [1] => array ( [pieces] => 1 [weight] => 1 [class] => ) [2] => array ( [pieces] => 1 [weight] => 1 [class] => ) ) ) [message] => array ( ) )
php javascript jquery arrays
No comments:
Post a Comment