我有一個ajax腳本,我有點了解,但仍需要一些額外的幫助。需要幫助學習ajax,從mysql抓取數據
$('.images').click(function(){
var imageId = $(this).attr('id');
alert(imageName);
$.ajax({
type: "get",
url: "imageData.php",
dataType: "json",
data: {getImageId: imageId},
error: function() {
alert("error");
},
success: function(data){
alert(imageId);
$("#images_"+imageId).html(data);
}
});
//$('#images_'+imageId).toggle();
});
我有一個代碼,它進入這個imageData.php文件
<?php
if(isset($_GET)){
$images = "";
$path = 'img/';
$imageId = $_GET['getImageId'];
$sql = mysql_query("SELECT * FROM images WHERE iID = '".$imageId."'");
while($row = mysql_fetch_array($sql)){
$images .= $path.$row['images'];
}
$json = json_encode($images);
?>
<img src='<?php echo $json;?>'/>
<?php
}
?>
爲什麼,當我嘗試從$圖像呼應的字符串,但它正確輸出,當我做輸出誤差echo $imageId;
?我試圖從MySQL輸出的東西,但沒有試圖輸出只是ID。
需要幫助,請,謝謝
當jQuery ajax返回值的時候,你會得到這個錯誤嗎?做一個'echo json_encode($ images);' – arma 2011-05-02 22:22:01
它不返回一個值,我只是得到錯誤。我試過做json_encode($ images);我不再有錯誤,但是,我也沒有得到一個成功的警報。 – hellomello 2011-05-02 23:03:46
我不確定是否可以提醒json嘗試使用console.log。螢火蟲控制檯響應是否爲空? – arma 2011-05-02 23:07:25