我的 AJAX 有问题。我的 javascript 文件无法将数据发送到 PHP 文件。我的 javascript 文件:
function updateTile(tile_no){
var ajaxRequest;
var color = document.getElementById("color_"+tile_no).value;
//alert($color);
var img_path = document.getElementById("url_"+tile_no).value;
//alert(url);
var title = document.getElementById("title_"+tile_no).value;
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Browser Error !");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById("box_tile"+tile_no).innerHTML = ajaxRequest.responseText;
}
else
{
document.getElementById("box_tile"+tile_no).innerHTML = '<img src=ajax-loader.gif /> <br /> ';
}
}
var url = "update.php?color="+color+"&url="+img_path+"&img_path="+title;
alert(url);
ajaxRequest.open("GET", url, true);
ajaxRequest.send(null);
}
alert(url);
节目update.php?color=#444444&url=http://somesite/image.jpg&img_path=Tile 1
。_ 我的update.php
文件:
<?php
$color_code = $_GET['color'];
$img_url = $_GET['img_path'];
$title = $_GET['title'];
echo 'Color Code :'.$color_code;
echo '<br />Image Path :'.$img_url;
echo '<br />Title :'.$title;
/*
echo '<div style="background:'.$color_code.';width:100%;height:100%;vertical-align:bottom;color:#f8f8f8;font-family:Trebuchet MS;"><img src="'.$img_url.'" /><span>'.$title.'</span></div>';
*/
?>
但是 PHP 的响应显示空结果!
Color Code :
Image Path :
Title :