使用jQuery的Ajax方法作為BLOB檢索圖像我最近提出了另一個(相關的)問題,這導致了這個后續問題:為輸入表單提交數據而不是文件閱讀jQuery.ajax()文檔(http://api.jquery.com/jQuery.ajax/),似乎接受的數據類型列表不包括圖像。我試圖使用jQuery.get(如果有必要的話,也可以使用jQuery.ajax)檢索圖像,將圖像存儲在Blob中,然后在POST請求中將其上傳到另一臺服務器。目前看來,由于數據類型的不匹配,我的圖像最終被損壞(大小與字節不匹配,等等)。執行此操作的代碼如下(它在CoffeeScript中,但應該不難解析):handler = (data,status) ->
fd = new FormData
fd.append("file", new Blob([data], { "type" : "image/png" }))
jQuery.ajax {
url: target_url,
data: fd,
processData: false,
contentType: "multipart/form-data",
type: "POST",
complete: (xhr,status) ->
console.log xhr.status
console.log xhr.statusCode
console.log xhr.responseText }jQuery.get(image_source_url, null, handler)如何將此圖像作為BLOB檢索?
使用jQuery的Ajax方法作為BLOB檢索圖像
慕尼黑5688855
2019-07-04 16:37:52
