PHPのコードをロードして応答するPHPページに値を渡そうとしています。私の問題は、返されたPHPコードが部分的に動作することです。ajaxでロードされたときにPHPの応答が部分的に動作する
AJAX:
$.ajax({
type: 'post',
url: 'bundles_drop.php',
data: {
time_selected:value,
networkType:networkType,
},
dataType : 'html',
success: function (response) {
// We get the element having id of display_info and put the response inside it
$("#bundles").html(response);
}
});
PHP:変数をエコー
if(isset($_POST['time_selected']))
{
$duration_selected = $_POST['time_selected'];
//$duration_selected = "day";
$client_network =$_POST['networkType']
}
Iは、AJAXポストを受け取る
は、コードの最初の行内で行うことができます。私の問題は、後でコードの行があり、変数が値を失います(コードのさまざまな部分でエコーを試みましたが、最初の数行でのみ動作します)。変数は、ハードコードしてPOST値を使用しないと値が保持されます。例:
$duration_selected = "day";
POST値の損失を引き起こす可能性のあるアイデアはありますか?
FULL PHPコード:
<?php
include 'arrays.php';
global $netMap;
global $netArray;
global $cM;
global $contABB;
if(isset($_POST['time_selected']))
{
$duration_selected = $_POST['time_selected'];
//$duration_selected = "day";
$client_net =$_POST['netType'];
//$duration_selected = "ugmtn";
$ds = $duration_selected;
$cn = $client_net;
$quantityOfCardsArray = array();
$bundle_duration = array();
$numberOfnets = count($netMap[$contABB]);
$netNames = array();
$net = array();
$netNames = $netMap[$contABB];
for($i=0;$i<$numberOfnets;$i++)
{
$thisnet=$netMap[$contABB][$i];
$numD=count($cardMap[$contABB][$thisnet]);
$bundle_duration = $cardMap[$contABB][$thisnet];
$netName=$netArray[$contABB]["$thisnet"]["netName"];
for($j=0;$j<$numD;$j++)
{
$cardIndex=$cardMap[$contABB]["$thisnet"]["$j"];
//var_dump($priceInLocal=$netArray[$contABB]["$thisnet"][0]["$cardIndex"]);
}
}
?>
<label id="bundlelbl" for="bundle">Please select a bundle</label>
<select id="bundle" name="bundle" required>
<?php
foreach($netNames as $index => $net){
if($net == $client_net)
{
$net_bundle=$netArray[$contABB]["$net"];
foreach($net_bundle as $value)
{
$value = (array) $value;
foreach ($value as $time => $bundle_details)
{
if($time == $duration_selected)
{
$detail_count = count($bundle_details);
$bundle_details = (array) $bundle_details;
//var_dump($bundle_details);
foreach($bundle_details as $data_value => $data_details)
{
$data_details = (array) $data_details;
echo "<option value='". $data_details['Item'] ."'> ". $data_details['Item'] ." worth ". $data_details['pr'] . "</option>";
}
}
}
}
}
}
}
?>
</select>
<fieldset>
<button type="submit">Submit</button>
私は全くその時点エコーdoesntの表示を超え
?>
<label id="bundlelbl" for="bundle">Please select a bundle</label>
<select id="bundle" name="bundle" required>
<?php
までポスト値をアップしてエコーができます。
は解決:
私はときに私はそれが他の方法でラウンドすることになった意図何のためにif文の中にforeachループを置いていました。ありがとう
は、PHPコードの残りの部分を表示します。それは範囲の問題かもしれません。 – aynber
'後で数行のコードを投稿できますか?そのif文で値が設定されている場合は、後で何かが上書きされる可能性があります。 – Halter