我在页面上的图像有问题。我正在使用 Javascript 创建元素,在 FireFox 中,我用来设置 innerHTML 的字符串似乎没有被正确解析。当使用无效的 GET 变量请求服务器页面时,我会看到这一点。它们看起来像这样(来自 PHP 脚本的错误处理程序):
GET[] = Array ( [shrink] => true [file_id] => \' file_id \' [refresh] => \' now.getTime() \' )
这只发生在大约 5% 的请求中,这使得解决起来很困难。我已经能够自己在 FireFox 中重现这一点,Firebug 会显示它试图获取的 URL 是:https ://www.domain.com/secure/%27%20+%20image_src%20+%20% 27
我在某处读到它可能与 FireFox 预取内容有关(现在无法在谷歌上搜索),因为它似乎只发生在 FireFox 上。在 about:config 中禁用预取确实可以防止问题发生,但我正在寻找另一种不涉及最终用户更改其配置的解决方案或解决方法。
这是细节和代码:我在 HTML 页面上有一个空的表格单元格。在页面的 JQuery 的 $(document).ready() 函数中,我使用 JQuery 的 $.ajax() 方法从服务器获取一些关于该单元格中应该包含什么的数据。它返回file_id
变量,为简单起见,我在下面设置了该变量。然后它将空表格单元格设置为具有 src 的图像,该图像指向将根据传递的 file_id 提供图像文件的页面。这部分代码最初是 JQuery,所以我将其更改为直接 Javascript,但这没有任何帮助。
//get data about image from server
//this is actually done through JQuery's $.ajax() but you get the idea
var file_id = 12;
//create the src for the img
//the refresh is to prevent the image from being cached ever, since the page's
//javascript will be it changes
//during the course of the page's life
var now = new Date();
var image_src = 'serve_image.php?shrink=true&file_id=' + file_id + '&refresh=' + now.getTime();
//create
document.getElementById('image_cell').innerHTML =
'<A target="_blank" href="serve_image.php?file_id=' + file_id + '">' +
'<IMG id=image_element src="' + image_src + '" alt="Loading...">' +
'</A>';`
任何帮助将不胜感激。谢谢!