何らかの理由で、私の php は、javascript が作成した json オブジェクトを読み取ることができません。
これがコンソールに出力されます。
{
"product": {
"shipsTo": "Please choose …",
"accountExec": "Please choose …",
"product": "Please choose …",
"productSize": "Please choose …",
"qty": "",
"comments": ""
},
"billing": {
"billingName": "",
"billingAttn": "",
"billingAddress1": "",
"billingAddress2": "",
"billingCity": "",
"billingState": "",
"billingZip": "",
"billingPhone": "",
"billingFax": "",
"billingEmail": "asdf@asdf.com"
}
}
私が記入した唯一のものはbillingEmail
.
これらの値は、フォームから約 15 個のフィールドを収集し、それらを JavaScript オブジェクトに入れることで取得します
$(document).ready(function(){
$('#CBS_submit').on("click", function(){
//validate
//collect information
var orderInfo = {};
orderInfo.product = {};
orderInfo.billing = {};
orderInfo.product.shipsTo = $('#CBS_ship_to_select option:selected').val();
orderInfo.product.accountExec = $('#CBS_account_execs_select option:selected').val();
orderInfo.product.product = $('#CBS_product_select option:selected').val();
orderInfo.product.productSize = $('#CBS_product_size_select option:selected').val();
orderInfo.product.qty = $('#CBS_qty').val();
orderInfo.product.comments = $('#CBS_comments').val();
//capture textarea information if other is selected for
//shipsTo, product, productSize
if ( get_selected_id ('CBS_ship_to_select') == 4 ) {
orderInfo.product.shipsTo = $('#other_ship_to_text').val();
}
if ( get_selected_id ('CBS_product_select') == 4 ) {
orderInfo.product.product = $('#other_product_text').val();
}
if ( get_selected_id ('CBS_product_size_select') == 4 ) {
orderInfo.product.productSize = $('#other_product_size_text').val();
}
orderInfo.billing.billingName = $('#CBS_billing_name').val();
orderInfo.billing.billingAttn = $('#CBS_billing_attn').val();
orderInfo.billing.billingAddress1 = $('#CBS_billing_address1').val();
orderInfo.billing.billingAddress2 = $('#CBS_billing_address2').val();
orderInfo.billing.billingCity = $('#CBS_billing_city').val();
orderInfo.billing.billingState = $('#CBS_billing_state').val();
orderInfo.billing.billingZip = $('#CBS_billing_zip').val();
orderInfo.billing.billingPhone = $('#CBS_billing_phone').val();
orderInfo.billing.billingFax = $('#CBS_billing_fax').val();
orderInfo.billing.billingEmail = $('#CBS_billing_email').val();
var orderInfoJSON = JSON.stringify(orderInfo);
console.log(orderInfoJSON);
$.ajax({
type: "POST",
url: "queries/submit_order.php",
data: "order_info=" + orderInfoJSON,
dataType: "json",
success: function (data) {
console.log('test');
}
});
});
});
次に、phpページでリクエストして、htmlに入れ始めます
<?php
$order_info = $_REQUEST['order_info'];
$order_info = json_decode($order_info, TRUE);
$msg = <<<EOD
<table style='width:600px; font-family:\"Helvetica\",\"Arial\", sans-serif; margin:15px' border="0">
のような変数にアクセスする
{$order_info['商品']['商品']}
しかし、何らかの理由で、何も送信されません。オブジェクトをコピー/貼り付けしても
$order_info = '{"product":{"shipsTo":"Please choose …","accountExec":"Please choose …","product":"Please choose …","productSize":"Please choose …","qty":"","comments":""},"billing":{"billingName":"","billingAttn":"","billingAddress1":"","billingAddress2":"","billingCity":"","billingState":"","billingZip":"","billingPhone":"","billingFax":"","billingEmail":"asdf@asdf.com"}}';
できます
私は何を間違っていますか?どうもありがとう!