我有通過$阿賈克斯()與jQuery調用服務器腳本和它運作良好,在Chrome或FF而不是在IE 8的jQuery + IE8的Ajax Json的解析錯誤
這是我的電話:
$.ajax({
url: 'location.php',
dataType: 'json',
success: function(data){
alert('Ajax made!');
$.each(data, function(key, val) {
var lat = null;
var lng = null;
var title = null;
var id = null;
$.each(val, function(index, vol) {
if(index == 'id')
id = vol;
else if(index == 'lng')
lng = vol;
else if(index == 'lat')
lat = vol;
else if(index == 'nombre')
title = vol;
});
// Create marker in the Google Map
createMaker(id,lat,lng,title);
});
},
error: function(jqXHR, textStatus, errorThrown){
// I get Error on IE 8
alert(jqXHR.responseText);
}
});
這
在服務器端代碼:
header('Content-type: application/json');
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Existe un problema al conectar a la base de datos. Disculpe las molestias');
mysql_select_db($dbname);
mysql_query('SET CHARACTER SET utf8');
$result = mysql_query("select id,lat,lng,nombre from location");
$rows = array();
while($r = mysql_fetch_assoc($result)) {
$rows[] = $r;
}
print json_encode($rows);
// close the connection
mysql_close($conn);
結果JSON是這樣的:
<!---- > [{「id」:「3」,「lat」:「19.700800」,「lng」:「 - 101.186972」,「nombre」:「Victor Manuel Mendoza Armas」}]
不知道爲什麼我的php在響應的頂部添加了<!---- >。
也許是這個問題?
是否包含可能正在輸出這些HTML註釋的文件? – AndrewR 2012-03-08 17:55:08
是的,這個問題,我包括一個PHP,它有一個HTML評論。謝謝 – 2012-03-08 18:00:49