" ) +
( (settings.imageUpload) ? "
" : "" ) +
"
" +
"
" + (function(){
return (settings.imageUpload) ? "
" +
- "" +
+ // 这里增加 id = {imageFileName},方便后面拿到文件数据
+ "" +
"" +
"
" : "";
})() +
@@ -131,7 +134,7 @@
return ;
}
- var fileInput = dialog.find("[name=\"" + classPrefix + "image-file\"]");
+ var fileInput = dialog.find("[name=\"" + imageFileName + "\"]");
fileInput.bind("change", function() {
var fileName = fileInput.val();
@@ -161,23 +164,45 @@
loading(false);
- var body = (uploadIframe.contentWindow ? uploadIframe.contentWindow : uploadIframe.contentDocument).document.body;
- var json = (body.innerText) ? body.innerText : ( (body.textContent) ? body.textContent : null);
+ // 注释掉官方写法,这里存在 iframe 跨域问题
+ // var body = (uploadIframe.contentWindow ? uploadIframe.contentWindow : uploadIframe.contentDocument).document.body;
+ // var json = (body.innerText) ? body.innerText : ( (body.textContent) ? body.textContent : null);
- json = (typeof JSON.parse !== "undefined") ? JSON.parse(json) : eval("(" + json + ")");
+ // json = (typeof JSON.parse !== "undefined") ? JSON.parse(json) : eval("(" + json + ")");
- if(!settings.crossDomainUpload)
- {
- if (json.success === 1)
- {
- dialog.find("[data-url]").val(json.url);
- }
- else
- {
- alert(json.message);
- }
- }
+ // if(!settings.crossDomainUpload)
+ // {
+ // if (json.success === 1)
+ // {
+ // dialog.find("[data-url]").val(json.url);
+ // }
+ // else
+ // {
+ // alert(json.message);
+ // }
+ // }
+ // 重写图片上传方法
+ var formData = new FormData();
+ formData.append(imageFileName, $("#" + imageFileName)[0].files[0]);
+ var action = settings.imageUploadURL + (settings.imageUploadURL.indexOf("?") >= 0 ? "&" : "?") + "guid=" + guid;
+ $.ajax({
+ url: action,
+ type: "POST",
+ data: formData,
+ dataType: "json",
+ async: false,
+ processData: false, // 使数据不做处理
+ contentType: false, // 不要设置 Content-Type 请求头
+ success: function (data) {
+ // 成功拿到结果放到这个函数 data就是拿到的结果
+ if (data.success === 1) {
+ dialog.find("[data-url]").val(data.url);
+ } else {
+ alert(data.message);
+ }
+ },
+ });
return false;
};
};