setting innerHTML - image not showing up but alt is
i have a page where i pull some html from an ajax request and then insert it into a div. the html is getting into the div correctly except that the image isn't showing up, but the alt text for it is. here is the html:
<div class='fltright'><img src='images/esl.jpg' alt="English as a Second Language"/></div><!-- end fltright --><p><span class='large'>Lorem 开发者_如何学Pythonipsum dolor sit amet,</span> consectetur adipiscing elit. Cras tempor semper tortor. </p>
is there any reason that the image would not show while the alt text would?
AJAX CODE:
function getData(fileName){
fileLoc = encodeURI("assets/"+fileName+".html")
//alert(fileLoc);
request.onreadystatechange = processData;
request.open("GET",fileLoc, false);
request.send();
//alert(request.readyState);
//alert(response);
//alert(request.status);
}
function processData(){
if (request.readyState==4){
if (request.status==200){
try{
response = request.responseText;
document.getElementsByClassName('content')[0].innerHTML = response;
} catch(e){
alert("Error: " +e.description);
}
}
else{
alert("An error has occured making the request");
}
}
}
I would check that the image is actually viewable in these senarios. A good way to check that is to right click and "View Image...". that will then ask your browser to specifically just request that image.
If you get Not Found
the requested image images/esl.jpg was not found on this server, then your url is incorrect.
If you get Forbidden
You don't have permission to access images/esl.jpg on this server. Then it is a permissions issue. As Endophage said you will then want to set the correct file and directory permissions for the Apache process to be able to view that image.
Often when using AJAX you forget where your images are in relation to where the document is. Try referencing the image from the root location, like this..
../images/esl.jpg
Seems to me that the image is actually in assets/images/esl.jpg, not images/esl.jpg
Consider the difference between where your page sits and the page you're scraping sits...
精彩评论