expressjs 支持umeditor 的圖片上傳

umedtor 的文件上傳 是form 提交。
請求的header
Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
 
在dialogs 裏面的image.js
                $('<iframe name="up"  style="display: none"></iframe>').insertBefore(me.dialog).on('load', function(){
                    var r = this.contentWindow.document.body.innerHTML;
                    if(r == '')return;
                    me.uploadComplete(r);
                    $(this).unbind('load');
                    $(this).remove();
 
                });
代表返回的是html。so,咱們要在express 返回制定的header Content-Type 必須是html
PS:umeditor 這樣作事兼容IE9如下的瀏覽器,若是不是Content-Type html. form 表單提交就變成下載文件了。
 
 
在expressjs 中
res.json 方法若是沒有設置,默認設置Content-Type=‘application/json’;
最後仍是調用send 方法
源碼以下
if (!this.get('Content-Type')) {
this.set('Content-Type', 'application/json');
}

return this.send(body);
這個不是咱們想要的response header。。兩種方案
 
一、手動設置
res.type('html');

在res.json
二、直接調用send 方法
result.state='SUCCESS';res.send(JSON.stringify(result))

相關文章
相關標籤/搜索