我正在使用 TinyMCE 并尝试上传图像。我的 HTML 页面由 Django 提供服务。请看下面我的图片上传处理程序(由 TinyMCE 提供)
images_upload_handler: function (blobInfo, success, failure, progress) {
var xhr, formData;
xhr = new XMLHttpRequest();
//xhr.withCredentials = true;
xhr.open('POST', 'http://localhost/tiny_upload.php');
xhr.setRequestHeader('x-requested-with', 'XMLHttpRequest')
xhr.upload.onprogress = function (e) {
progress(e.loaded / e.total * 100);
};
xhr.onload = function () {
var json;
if (xhr.status < 200 || xhr.status >= 300) {
failure('HTTP Error: ' + xhr.status);
return;
}
json = JSON.parse(xhr.responseText);
if (!json || typeof json.location != 'string') {
failure('Invalid JSON: ' + xhr.responseText);
return;
}
success(json.location);
};
xhr.onerror = function () {
failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status +
' Message:' + xhr.responseText);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
}
MM们
相关分类