我想知道您是否能再次帮助我...
我正在使用ajax调用php页面,以将clientwidth值传递给它,以便可以适当调整图像大小。我从哪里进行ajax调用的位置在调用页面的“主” div内,但是未显示图像。你能帮忙吗?
我的ajax呼叫:
<script>
// Get the HTTP Object
function getHTTPObject(){
if (window.ActiveXObject)
return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest)
return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}
w=document.documentElement.clientWidth;
// Implement business logic
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open("GET", "imagedisplay.php?width=" + w + "&id=" + <?php print $row['id'] ?> +"&imageno="+<?php print $imageno ?>, true);
httpObject.send(null);
}
var httpObject = null;
</script>
...以及相关的php文件...
<?php
include "connection.php";
$id=$_GET["id"];
$w=$_GET["width"];
$imageno=$_GET["imageno"];
$query = "Select * from courses where id = '$id'";
$result = mysqli_query($connection,$query) or die ("Error in query: $query. ".mysqli_error($connection));
while($row = mysqli_fetch_array($result)) {
$table="<table><tr>";
switch ($imageno) {
case 1:
$photowidth=$w;
break;
case 2:
$photowidth=$w/2;
break;
case 3:
$photowidth=$w/3;
break;
case 4:
$photowidth=$w/2;
break;
case 5:
$photowidth=$w/3;
break;
case 6:
$photowidth=$w/3;
break;
}
if ($row['iamge1']!=NULL) {
$table .="<td><img src=\"../".$row['image1']."\" width=\"".$photowidth."\" border=\"0\"></td>";
}
if ($row['image2']!=NULL) {
$table .="<td><img src=\"../".$row['image2']."\" width=\"".$photowidth."\" border=\"0\"></td>";
}
if ($row['image3']!=NULL) {
$table .="<td><img src=\"../".$row['image3']."\" width=\"".$photowidth."\" border=\"0\"></td>";
}
if ($row['image4']!=NULL) {
$table .="<td><img src=\"../".$row['image4']."\" width=\"".$photowidth."\" border=\"0\"></td>";
}
if ($row['image5']!=NULL) {
$table .="<td><img src=\"../".$row['image5']."\" width=\"".$photowidth."\" border=\"0\"></td>";
}
if ($row['image6']!=NULL) {
$table .="<td><img src=\"../".$row['image6']."\" width=\"".$photowidth."\" border=\"0\"></td>";
}
}
$table.="</tr><table>";
print $table;
?>
我知道正在调用php页面,因为当我在其中引入一些错误时,它在apache日志中报告了。我还手动将键/值对输入到文件中,然后图像出现在页面上。提前...