我正在尝试一次性获取 json 中的几部分数据,例如
<?php
$host = "localhost";
$user = "root";
$pass = "";
$databaseName = "world";
$tableName = "city";
$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
$result = mysql_query("SELECT * FROM $tableName limit 15"); //query
//fetch result
$jsonData = array();
while ($array = mysql_fetch_row($result)) {
$jsonData[] = $array;
}
//first section
echo '<section id="stuff">';
echo json_encode($jsonData);
echo '</section>';
//section two ....
?>
我返回包装在 html5 部分标记中的 json
<section id="stuff">[["1","Kabul","AFG","Kabol","1780000"],["2","Qandahar","AFG","Qandahar","237500"],["3","Herat","AFG","Herat","186800"],["4","Mazar-e-Sharif","AFG","Balkh","127800"],["5","Amsterdam","NLD","Noord-Holland","731200"],["6","Rotterdam","NLD","Zuid-Holland","593321"],["7","Haag","NLD","Zuid-Holland","440900"],["8","Utrecht","NLD","Utrecht","234323"],["9","Eindhoven","NLD","Noord-Brabant","201843"],["10","Tilburg","NLD","Noord-Brabant","193238"],["11","Groningen","NLD","Groningen","172701"],["12","Breda","NLD","Noord-Brabant","160398"],["13","Apeldoorn","NLD","Gelderland","153491"],["14","Nijmegen","NLD","Gelderland","152463"],["15","Enschede","NLD","Overijssel","149544"]]</section>
这是我的jQuery
$.ajax({
url: 'getdata.php',
data: "",
dataType: 'html',
success: function(data)
{
//console.log(data);
var thedata = $(data).filter($("#stuff"));
console.log(thedata);
}
});
这不起作用。如何仅选择部分标签内的数据?