内容类型无效:application / x-www-form-urlencoded;字符集= UTF-8

时间:2018-06-04 18:58:44

标签: jquery file-upload coldfusion

我在将请求从jQuery发送到CFC时收到此错误。

我从jquery获取文件路径并使用该路径我正在加载文件并将其发送到数据库。

jQuery的:

$("#submitbtn").click(function() {
  var fileInput = document.getElementById("fileupload");
  var filename = fileInput.files[0].name;
  var filepath = $("#fileupload").val();
  var filetype = fileInput.files[0].type;
  $.ajax({
    url: "_cfc/recommendation.cfc?method=evaluationattachment",
    type: "POST",
    data: {
      filepath: filepath,
      filename: filename,
      filetype: filetype
    },
  }).done(function(response) {
    console.log(response);

  }).fail(function(jqXHR, textStatus, errorMessage) {
    //window.location.href = "error.cfm";
  });

CFC:

<cffunction name="evaluationattachment" access="remote" returntype="any" returnformat="json">
  <cfargument name="filepath" type="string" required="no">
  <cfargument name="filename" type="string" required="no">
  <cfargument name="filetype" type="string" required="no">  
  <cfset dest = getTempDirectory()>
  <cffile action="upload" file="#filepath#" destination="#dest#" result="uploadResult" nameconflict="makeunique">
  <cfif uploadResult.fileWasSaved>
    <cfset theFile = uploadResult.serverDirectory & "/" & uploadResult.serverFile>
    <cffile action="readbinary" file="#theFile#" variable="attachment">
    <cfstoredproc procedure="recommendation.evaluationattachment">
      <cfprocparam cfsqltype="CF_SQL_BLOB" value="#attachment#" type="in">
      <cfprocparam cfsqltype="cf_sql_varchar" value="#filename#" type="in" maxlength="50">
      <cfprocparam cfsqltype="cf_sql_varchar" value="#filetype#" type="in" maxlength="12">
      <cfprocparam cfsqltype="cf_sql_varchar" value="#attachment_id#" type="out">
    </cfstoredproc>
    <cfset r = {"attachmentid"="#attachment_id#"}>
    <cfreturn r>
  </cfif>
</cffunction>

0 个答案:

没有答案