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);
  });
}
相关文章
|
6月前
|
前端开发 JavaScript
Error_ Multipart_ Boundary not foun
Error_ Multipart_ Boundary not foun
96 0
|
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的解决方案
246 0
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.
728 0
|
应用服务中间件 nginx Windows
1113: No mapping for the Unicode character exists in the target multi-byte code page
1113: No mapping for the Unicode character exists in the target multi-byte code page
663 0
1113: No mapping for the Unicode character exists in the target multi-byte code page
|
Java
java实战小结-Controller报错:Content type ‘multipart/form-data;boundary=----WebKitFormBoundaryxxxx not supp
java实战小结-Controller报错:Content type ‘multipart/form-data;boundary=----WebKitFormBoundaryxxxx not supp
401 0
how is opportunity detail page display first item by default
how is opportunity detail page display first item by default
91 0
how is opportunity detail page display first item by default
How to enable multiple text type for Product
Created by Jerry Wang, last modified on Oct 31, 2014
127 0
How to enable multiple text type for Product
JakartaEE Struts2 The content of element type "package" must match "(result-types?,interceptors?,...
异常信息: The content of element type "package" must match "(result-types?,interceptors?,default-interceptor- ref?,default-action...
1078 0