Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript firefox中存在多个问题,但在chrome中正常工作,没有单一问题_Javascript_Ajax_Reactjs_Form Data_Superagent - Fatal编程技术网

Javascript firefox中存在多个问题,但在chrome中正常工作,没有单一问题

Javascript firefox中存在多个问题,但在chrome中正常工作,没有单一问题,javascript,ajax,reactjs,form-data,superagent,Javascript,Ajax,Reactjs,Form Data,Superagent,我在firefox上有很多问题,但在chrome上没有 1)类型错误中的问题:response.body为空。 2)上载图像时,我得到了类型错误:FormData.constructor的参数1未实现接口HTMLFormElement。 显示问题的代码如下 对于第1个问题(我已经为此使用了superagent) 第二期 let image = []; class RenderPhotos extends React.Component { constructor(props, co

我在firefox上有很多问题,但在chrome上没有

1)类型错误中的问题:response.body为空。

2)上载图像时,我得到了类型错误:FormData.constructor的参数1未实现接口HTMLFormElement。

显示问题的代码如下

对于第1个问题(我已经为此使用了superagent)

第二期

  let image = [];
 class RenderPhotos extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.state = {
            files: []
        };
    }

    onDrop(files) {
      console.log('Received files: ', files);
      this.setState({
          files: files
      });

    image = new FormData(files);
    $.each(files,function(i,file){
      image.append('image',file);
    });

    } 
为什么这段代码在chrome上运行而不是在firefox上运行?要使此代码在所有浏览器中工作,应更改哪些内容

关于错误2:如果将a传递给
FormData
构造函数,则它必须是HTML
元素,而您的代码中似乎不是这样。因此,只需删除参数:

image = new FormData();
更新:


关于错误1:正如您自己发现的那样,请求需要一个接受头
application/json
。由于Chrome和Firefox默认接受头的不同,服务器似乎为Chrome而不是Firefox返回json负载。不管怎样,显式标题解决了这个问题。

它就像一个符咒。您知道第一个问题的原因吗?@millan no。如果您在Chrome和Firefox中运行时比较网络开发工具中的HTTP请求和响应,也许您可以检测到原因。谢谢,我将诊断问题。我将标题设置为set('Accept','application/json')它在firefox中工作,但不知道为什么没有这个firefox会抛出错误。你能把这篇文章贴到第1期吗?这样我就可以把它标记为已回答了。将您的发现添加到答案中
image = new FormData();