【问题标题】:get FormData call ajax to symfony 4获取 FormData 调用 ajax 到 symfony 4
【发布时间】:2020-04-08 00:09:11
【问题描述】:

我的代码js是:

fetch(img).then(response => response.blob()) //img is canvas with method toBlob('image/png')
  .then(blob => {
    console.log(blob)
    const fd = new FormData();
    fd.append("fileName", blob, "file.ext");
    return fetch("/sendImg", {
      method: "POST",
      fd
    })
  })
  .then(response => response.ok)
  .then(res => console.log(res))
  .catch(err => console.log(err));

Symfony 无法处理任何事情:

 $_REQUEST['fileName']) || isset($_FILES['fileName']) || $request->files->get('fileName')

【问题讨论】:

    标签: javascript ajax symfony symfony4


    【解决方案1】:

    您应该在请求中设置 body 属性,因为现在您没有发送表单数据,而是设置了 fd 属性

    fetch("/sendImg", {
          method: "POST",
          body: fd // here
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-27
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 2019-01-14
      • 1970-01-01
      • 2012-01-15
      • 2018-07-13
      相关资源
      最近更新 更多