您好我有以下问题。我正在尝试访问我在 javascript 中从数据库中查询的数据,然后执行一个函数
<?php
$sql_sp1 = "{call [IR_CMS].[dbo].[usp_GetPropertyPriceAndAvail](?,?)}";
$params = array( array($ChaletID, SQLSRV_PARAM_IN),
array($BoardBasisID, SQLSRV_PARAM_IN));
$result_sp1 = sqlsrv_query( $conn, $sql_sp1, $params);
if( $result_sp1 === false)
{
echo "2. Get property price and avail - Error in query preparation/execution.\n";
die( print_r( sqlsrv_errors(), true));
}
$data_sp1 = array();
while($row_sp1 = sqlsrv_fetch_array($result_sp1, SQLSRV_FETCH_ASSOC)) {
$data_sp1[] = $row_sp1;
}
//echo '<pre>';
//print_r($data_sp1);
//echo '</pre>';
?>
<script>
availdata = <?php echo json_encode($data_sp1); ?>;
</script>
如果我回显数据,它会产生类似这样的内容
[{"PropertyID":138,"PropertyName":"Yves","ShowAvail":"Y","PropertyStartDateID":509495,"StartDate":"2012-12-08","DurationDesc":"7 晚" ,"Saving":null,"Price":null,"Avail":"4","LiveSeason":1,"SeasonDesc":"2012-13","BoardBasisDesc":"Catered","PropTypeDesc":" Chalet Hotel","ResortName":"Les Arcs","CountryDesc":"France","FTA":"FTA","Sole_Use":0,"IsInShorlist":0}];
但我无法在 javascript 中访问它。如果我直接将数据复制并粘贴到我的 javascript 中,它将起作用,但如果我尝试动态访问它,则不会。是的,我已经完成了我的研究,我很确定这应该有效任何想法我做错了什么