我在页面上遇到图像问题。我使用Javascript来创建元素,并且在FireFox中,似乎我用来设置innerHTML的字符串未被正确解析。当服务器页面被请求使用无效的GET变量时,我会看到这一点。他们看起来像这样(从PHP脚本的错误处理程序):在FireFox中为img元素设置src时出现Javascript问题 - 字符串解析错误?
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预取内容有关(现在无法找到它googling ),因为它似乎只发生在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>';`
任何帮助将不胜感激。谢谢!
Wayyy阅读很多... – 2010-05-19 13:08:23
真正的“file_id”值究竟是什么样子? – Pointy 2010-05-19 13:46:57
它们是整数,通常在500 - 1500的范围内。 – Kevin 2010-05-19 15:02:04