我是两个网站的网站管理员。第一个生成一个带有动态图像的网页。我需要通过其他网站的Javascript获取此图片的动态伪随机URL。
此图像带有一个ID="main-img"
标签。
是否可以使用服务器端语言来获取此图像的SRC
元素?
我已经尝试过使用XMLHttpRequest
对象,但是在request.responseText
处我得到了一个空字符串。
有什么建议吗?谢谢。
function makeHttpObject()
{
try {return new XMLHttpRequest();}
catch (error) {alert(error)}
try {return ActiveXObject("Msxml2.XMLHTTP");}
catch (error) {alert(error)}
try {return ActiveXObject("Microsoft.XMLHTTP");}
catch (error) {alert(error)}
}
function httpGet(theUrl)
{
try
{
var request = makeHttpObject();
request.open("GET", theUrl, true);
request.send(null);
request.onreadystatechange = function() {
if (request.readyState == 4)
{
alert(request.responseText);
}
else
{
alert('Nothing to show')
}
}
}
catch (error) {alert(error)}
}