尝试将php文件中的数据回显到iOS 7.1.2中的移动版Safari时出现问题。这是php代码:
function swapFlights()
{
var url;
redirect = 1;
airline = <?php echo 'PDT'; ?>;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
在iPhone 5S的移动版Safari中,输出如下:
function swapFlights()
{
var url;
redirect = 1;
airline =
2cc1
PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
看似随机的&#34; 2cc1&#34;是插话,我不能为我的生活找出原因。它在解析JavaScript时导致SyntaxError,导致页面上的所有JavaScript都无法使用。在我尝试过的所有其他浏览器(桌面Safari,Firefox)中,代码按照人们的预期正确输出:
function swapFlights()
{
var url;
redirect = 1;
airline = PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
任何想法,或者这更可能是移动Safari本身的错误?我在互联网上搜索过,但似乎找不到任何其他问题。
将php更改为:
redirect = 1;
<?php echo 'airline = PDT'; ?>;
导致未知字符略有不同,并在输出中出现:
redirect = 1;
2ccb
airline = PDT;
我应该明确指出,我的目标是取代“PDT”&#39;使用字符串变量$ airline。我将变量更改为文字&#39; PDT&#39;我想我可能对变量的数据类型有问题,但事实并非如此。