我有一个名为storage.html的HTML文件,它将图像数据存储为base64编码的字符串:
<img class="bi x0 y0 w1 h1" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABEoAAAWpCAIAAAD.....==">
和其他div。
我将此存储的数据加载到另一个HTML文件draw.html中,加载为:
function refresh_show_last_change()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("page-container").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("POST", "storage.html", true);
xmlhttp.send();
}
page-container是我想要给出storage.html内容的div 但是我在这个问题上得到了一个错误:图像(从storage.html编码的base64无法加载)
错误是:
Failed to load resource: net::ERR_INVALID_URL data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABEoAAAWpCAIAAADhg2AvAAAACXBIW…8AAADkDQAAgLwBAACQNwAAAPIGAAAAAADgr8p7AwAAjDhwFZJdGpWVPAAAAABJRU5ErkJggg==
有人可以告诉我如何纠正这个问题。我希望存储.html中的div和base64图像src在xmlhttp.responsetext中提取
提前致谢!
我如何将storage.html中的页面容器innerhtml存储为:
function save() {
// 1. Create XHR instance - Start
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
else {
throw new Error("Ajax is not supported by this browser");
}
// 1. Create XHR instance - End
var edited_data = document.getElementById("page-container").innerHTML;
// 3. Specify your action, location and Send to the server - Start
xhr.open('POST', 'editor_change.php');
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("edited_data=" + edited_data);
// 3. Specify your action, location and Send to the server - End
}