Posted content type isn't multipart/form-data

简介: Posted content type isn't multipart/form-data

在有文件上传的表单提交过程中,搞不好就会报Posted content type isn't multipart/form-data的错误。


解决办法


<form class="form-horizontal" action="${ctx}/project/addProjectReback?callbackType=closeCurrent" 
  enctype="multipart/form-data" method="post" οnsubmit="return iframeCallback(this, dialogAjaxDone)">
<input type="file" name="image" class="required" accept="image/gif, image/jpeg, image.png">


enctype="multipart/form-data"必须有这段代码。

必须对该上传文件类型的表单进行封装,区分普通的表单上传。

/**
 * 带文件上传的ajax表单提交
 * 
 * @param {Object}
 *            form
 * @param {Object}
 *            callback
 */
function iframeCallback(form, callback) {
  YUNM.debug("带文件上传处理");
  var $form = $(form), $iframe = $("#callbackframe");
  // 富文本编辑器
  $("div.editor", $form).each(
      function() {
        var $this = $(this);
        var editor = "<input type='hidden' name='" + $this.attr("name") + "' value='"
            + $.base64.btoa($this.html()) + "' />";
        $form.append(editor);
      });
  var data = $form.data('bootstrapValidator');
  if (data) {
    if (!data.isValid()) {
      return false;
    }
  }
  if ($iframe.size() == 0) {
    $iframe = $("<iframe id='callbackframe' name='callbackframe' src='about:blank' style='display:none'></iframe>")
        .appendTo("body");
  }
  if (!form.ajax) {
    $form.append('<input type="hidden" name="ajax" value="1" />');
  }
  form.target = "callbackframe";
  _iframeResponse($iframe[0], callback || YUNM.ajaxDone);
}
function _iframeResponse(iframe, callback) {
  var $iframe = $(iframe), $document = $(document);
  $document.trigger("ajaxStart");
  $iframe.bind("load", function(event) {
    $iframe.unbind("load");
    $document.trigger("ajaxStop");
    if (iframe.src == "javascript:'%3Chtml%3E%3C/html%3E';" || // For
    // Safari
    iframe.src == "javascript:'<html></html>';") { // For FF, IE
      return;
    }
    var doc = iframe.contentDocument || iframe.document;
    // fixing Opera 9.26,10.00
    if (doc.readyState && doc.readyState != 'complete')
      return;
    // fixing Opera 9.64
    if (doc.body && doc.body.innerHTML == "false")
      return;
    var response;
    if (doc.XMLDocument) {
      // response is a xml document Internet Explorer property
      response = doc.XMLDocument;
    } else if (doc.body) {
      try {
        response = $iframe.contents().find("body").text();
        response = jQuery.parseJSON(response);
      } catch (e) { // response is html document or plain text
        response = doc.body.innerHTML;
      }
    } else {
      // response is a xml document
      response = doc;
    }
    callback(response);
  });
}
相关文章
|
4月前
|
前端开发 开发者
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
46 1
|
4月前
|
前端开发 JavaScript
Error_ Multipart_ Boundary not foun
Error_ Multipart_ Boundary not foun
|
6月前
|
JSON 数据格式
Content type ‘multipart/form-data;boundary=------57031299820747271;charset=UTF-8‘ not supported的解决方案
Content type ‘multipart/form-data;boundary=------57031299820747271;charset=UTF-8‘ not supported的解决方案
60 0
|
10月前
Warning: [antd: Form.Item] `defaultValue` will not work on controlled Field. You should use `initialValues` of Form instead.
Warning: [antd: Form.Item] `defaultValue` will not work on controlled Field. You should use `initialValues` of Form instead.
298 0
|
Java
java实战小结-Controller报错:Content type ‘multipart/form-data;boundary=----WebKitFormBoundaryxxxx not supp
java实战小结-Controller报错:Content type ‘multipart/form-data;boundary=----WebKitFormBoundaryxxxx not supp
302 0
|
JavaScript 前端开发
sendData to ABAP backend via multiple form content type
Created by Jerry Wang, last modified on Aug 20, 2014
sendData to ABAP backend via multiple form content type
How to enable multiple text type for Product
Created by Jerry Wang, last modified on Oct 31, 2014
105 0
How to enable multiple text type for Product

热门文章

最新文章