Ajax images not showing
I have a mysql database which stores the paths of some images on a network drive.
I thought that using Ajax, I would be able to dynamically generate image tags to display these images in the browser as each image tag would inovoke a new GET request with the path relative to the browser.
The web server has a small HDD and I don't want to have to duplicate everything - so can't store large numbers of images on the server.
My PHP seems to generate the image tags correctly however the broswer does not show the images.
PHP code:
$sql = "SELECT ID,Link FROM tblStorePictures WHERE StoreNumber = $sto";
$result = mysql_query($sql,$dblink) or die(mysql_error());
$row = mysql_fetch_array($result);
$id = $row['ID'];
echo "<img src='file://".$row['Link']."' alt='Image' id=$id>";
The image tags (as viewed in firebug) end up looking like this:
<img id="57" alt="Image" src="file://x:/Image1.jpg">
I have tried various things but nothing works:
Dynamically generating the image tags with javascript using the document.createElement("img") method and setting attributes for the source etc.
Using javascript to set innerHTML.
In all cases I've got the tags to generate correctly, but I still see nothing in the browser but the alt text.
Any s开发者_JS百科uggestions welcome.
What you are facing is a security feature of your browser. In fact, your browser will not follow links to local web pages (it means file://
urls) because the page you are viewing is not a local one (you are not at file://.../.../page.html
). Therefore the browser sees a website on the network trying to access a file on your hard drive, and denies access to it for obvious reasons.
It's not an issue with AJAX but an issue with the link to the file. I can almost guarantee your linking is wrong somehow. If you enter the exact link the the file "file://x:/Image1.jpg" in the url filed of the browser, and nothing shows up, it proves there's an issue with your file links.
精彩评论