我试图将值传递给PHP页面,该页面将响应要加载的PHP代码。我的问题是返回的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']
}
当我收到AJAX帖子时,可以在第一行代码中完成回显变量。我的问题是稍后的代码行,变量会松散它们的值(我尝试在代码的不同部分回显,但只适用于前几行)。
如果我对它们进行硬编码并且不使用POST值,变量只保留它们的值。例如
$duration_selected = "day";
关于可能导致POST值丢失的任何想法?
完整的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>
我可以回复帖子的值直到
?>
<label id="bundlelbl" for="bundle">Please select a bundle</label>
<select id="bundle" name="bundle" required>
<?php
超过该点,回声根本不显示。
解决:
我已经在if语句中放置了一个foreach循环,而对于我想要的它应该是另一种方式。感谢
答案 0 :(得分:0)
在范围区域(在if语句中)声明变量时,只能在if中访问它们。之前声明它们并将它们设置为whithin,如下所示:
$duration_selected = '';
$client_network = '';
if( isset( $_POST['time_selected'] ) )
{
$duration_selected = $_POST['time_selected'];
//$duration_selected = "day";
$client_network =$_POST['networkType'];
}
答案 1 :(得分:0)
如果您在<DataTemplate>
<Grid>
<TextBox ContextMenuOpening="{Binding ??WHAT GOES HERE?? }" />
</Grid>
</DataTemplate>
块之外使用$duration_selected
和$client_network
,则除非至少执行一次,否则它将被取消定义。
因此,请确保访问前两个变量的代码在上述if( isset( $_POST['time_selected'] ) )
块中运行。
示例:
if