【发布时间】:2011-03-30 05:18:06
【问题描述】:
var txtimg = new Image(); //img holder
$(txtimg).load(function () {
$("#div").append(this);
}).error(function () {
// notify the user that the image could not be loaded
alert('error loading text');
}).attr('src', webroot + '?drawtxt='+text.content);
上面的代码使用 jQuery load 加载图像。它在 text.content 是普通字符时起作用。但是,当 text.content 包含 URL 中不允许的特殊字符时,图像不会加载,例如 '&' 字符,甚至编码为 '%26'。
因此,我正在寻找一种使用 ajax 发送一些数据的方法,该方法允许使用特殊字符,同时也能够返回图像。
如果我使用$.ajax(),返回值可以包含二进制图像流吗?如果不是,还有哪些其他方法可以使用特殊字符进行 ajax 调用并同时返回图像?
【问题讨论】:
-
为什么不将图像存储在亚马逊或其他东西(而不是数据库)中,然后存储 URL?这不是更容易吗?
标签: php jquery ajax image special-characters