gpt4 book ai didi

PHP 脚本和 HTML - 这适用于 Firefox 和 Chrome,但不适用于 IE

转载 作者:可可西里 更新时间:2023-11-01 00:48:09 25 4
gpt4 key购买 nike

以下是我尝试在我的网站上使用的内容,此 php 页面在 Firefox 和 Chrome 中显示时没有任何问题。

出于某种原因,它似乎无法在 IE 中运行(在 8 和 9 上测试过)我真的不知道这里出了什么问题。

我在 IE8 中遇到的错误是“不是有效的二维数组”,这似乎来自谷歌托管的 .js

我想知道为什么这只发生在 IE8 而不是 Chrome 或 Firefox 中?

<?php
// Top snippet of code comes from:
// www.ip2nation.com/ip2nation/Sample_Scripts/Output_Full_Country_Name
// and adapted as necessary.

$server = 'sanitized'; // MySQL hostname
$username = 'sanitized'; // MySQL username
$password = 'sanitized'; // MySQL password
$dbname = 'sanitized'; // MySQL db name

// 1 address per line, or feed with a DB if you're feeling clever.
$lines = file('blocklist.txt');

$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$bans = array();
foreach ($lines as $lnum => $line)
{
$l=rtrim($line);
$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$l.'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';
list($cc) = mysql_fetch_row(mysql_query($sql));

if ($cc != "")
if(empty($bans["$cc"]))
{
$bans["$cc"] = 1;
}
else
{
$bans["$cc"]++;
}

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
<script type='text/javascript' src='https://www.google.com/jsapi'>
</script>
<script type='text/javascript'>

google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawRegionsMap);

function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country','Blocks'],
<?php
foreach ($bans as $key => $value)
print"['$key', $value],\n";
?>
]);

var options = {
backgroundColor : '#baecfd',
colors : ['#FFFFFF', '#FF0000']
};

var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
<title></title>

<style type="text/css">
div.c1 {width: 900px; height: 500px;}
</style>
</head>
<body>
<div id="chart_div" class="c1"></div>
</body>
</html>

在IE中编译时的代码是:

<html>                                                                                                                                                                              
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawRegionsMap);

function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country','Blocks']
['Japan', 11]
['United States', 45]
['Argentina', 1]
['Brazil', 1]
['Bosnia and Herzegovina', 1]
['Germany', 4]
['France', 2]
['Russia', 5]
['China', 24]
['Thailand', 1]
['New Zealand (Aotearoa)', 1]
['Turkey', 1]
['Korea (South)', 6]
['Panama', 2]
['Taiwan', 6]
['Canada', 14]
['Luxembourg', 1]
['United Kingdom', 1]
['Philippines', 1]
['Singapore', 3]
['Switzerland', 2]
['Hong Kong', 2]
]);

var options = {
backgroundColor : '#25383c',
colors : ['#FFFFFF', '#FF0000']
};

var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>

在 Chrome 中编译时的代码是:

<html>                                                                                                                                                                              
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawRegionsMap);

function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country','Blocks'],
['Japan', 11],
['United States', 45],
['Argentina', 1],
['Brazil', 1],
['Bosnia and Herzegovina', 1],
['Germany', 4],
['France', 2],
['Russia', 5],
['China', 24],
['Thailand', 1],
['New Zealand (Aotearoa)', 1],
['Turkey', 1],
['Korea (South)', 6],
['Panama', 2],
['Taiwan', 6],
['Canada', 14],
['Luxembourg', 1],
['United Kingdom', 1],
['Philippines', 1],
['Singapore', 3],
['Switzerland', 2],
['Hong Kong', 2],
]);

var options = {
backgroundColor : '#25383c',
colors : ['#FFFFFF', '#FF0000']
};

var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>

最佳答案

var data = google.visualization.arrayToDataTable([
['Country','Blocks'],
<?php
foreach ($bans as $key => $value)
print"['$key', $value],\n";
?>
]);

将返回:

var data = google.visualization.arrayToDataTable([
['key1', value1],
['key2', value2],
]);

第二个末尾的额外逗号会打断它。看这个:

http://www.openjs.com/articles/ie/array_comma_problem.php

var sample = {
'hello':'world',
'foo':'bar', //This is 'the last comma'
}

alert("Hello World");

http://jsfiddle.net/A5VMW/

在大多数浏览器中,最后的 ',' 是可选的 - 它的存在不会对脚本产生任何影响。但是 IE 会决定做一些无法解释的事情——它只是忽略那段代码之后的所有内容。在 IE 浏览器中永远不会看到“Hello World”警报。

另见:https://stackoverflow.com/a/5139395/504299 :

Historically speaking, ES3 disallowed having a trailing comma when defining an object literal. This was one thing that IE did get right, but most other bowser vendors went south and did allow the trailing comma. So technically it was a bug in the other browsers that supported it.

关于PHP 脚本和 HTML - 这适用于 Firefox 和 Chrome,但不适用于 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13533413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com