gpt4 book ai didi

javascript - Firefox 与 jquery.post 的问题

转载 作者:行者123 更新时间:2023-11-28 09:47:53 25 4
gpt4 key购买 nike

我有一个函数,可以从 Controller 检索 Base64 编码的图像并在新窗口中显示该图像。它在 Chrome 中完美运行,但在 Firefox 中失败,出现错误“格式不正确”和“不支持请求方法“GET””。我不明白为什么会出现这种情况,因为我使用的是 post,而不是 get...

相关代码部分是:

function showPicture(label) {
$.post( 'picture-view', { labelname: label }, function(ImageSrc) {
var img = new Image;
img.src = "data:image/png;base64," + ImageSrc;
img.style.position = 'fixed';
img.style.left = '0';
img.style.top = '0';
img.onload = function() {
var newWindow = window.open("", label,"scrollbars=0, toolbar=0, width="+myImage.width+", height="+myImage.height);
creativeWindow.document.documentElement.innerHTML='';
creativeWindow.document.documentElement.appendChild(img);
}​
});}

编辑此外,如果有任何有关可帮助您了解有关此 Material 的更多信息的无障碍书籍或网站的建议,我们将不胜感激。

编辑 #2 我还应该补充一点,当我尝试将 img.src 写入控制台时,它显示为 [objectXMLDocument]。

编辑 #3 我已跟踪错误,发现返回的 ImageSrc 应该是字符串,但被解释为 XML 对象。它包含反斜杠这一事实导致了“格式不正确”错误。我现在的问题是:如何让 $.post 或 $.ajax 在 Firefox 中返回字符串(Chrome 中已经这样做了)。

最佳答案

我可能会尝试使用.ajax。它还允许您提供后备内容。

与其使用 post 发送图像,不如将图像托管在您的服务器上并通过 src 加载图像。这将是一种更干净的方法。

例如

$.ajax({

type: "POST",
data: "",
url: yourURL,
error: function() {
//The call was unsuccessful
//Place fallback content/message here
},
success: function(data) {
//The call was successful

//Open new window
var newWindow = window.open("", label,"scrollbars=0, toolbar=0, width="+myImage.width+", height="+myImage.height);
creativeWindow.document.documentElement.innerHTML='';

//Create the image
var image = document.createElement("img");
image.src = data;

//Attach image to new window
creativeWindow.document.documentElement.appendChild(image);

}

});

关于javascript - Firefox 与 jquery.post 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11522688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com