Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.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 用fetch响应加载页面_Javascript_Reactjs - Fatal编程技术网

Javascript 用fetch响应加载页面

Javascript 用fetch响应加载页面,javascript,reactjs,Javascript,Reactjs,我试图在div中显示我的url/PaisForm的内容,但不起作用。我的代码是: componentDidMount(){ fetch('/PaisForm') .then(function(response) { return response.text(); }) .then(function(body) { document.querySelector('.Pais').innerHTML = body; }); }

我试图在div中显示我的url/PaisForm的内容,但不起作用。我的代码是:

componentDidMount(){
    fetch('/PaisForm')
    .then(function(response) {
        return response.text();
    })
    .then(function(body) {
        document.querySelector('.Pais').innerHTML = body;
    });
}
  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
这是我的部门:

render() {
     return(

       <div className= "Pais">
       </div>
      );
    }
}
  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
render(){
返回(
);
}
}
当我使用console.log函数(body)时,我可以阅读以下内容:

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
您需要启用JavaScript才能运行此应用程序

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
您可以将网络字体、元标记或分析添加到此文件。
构建步骤将把捆绑的脚本放入标记中。
要开始开发,请运行“npm开始”或“纱线开始”。
要创建生产捆绑包,请使用“npm运行构建”或“纱线构建”。
感谢您的帮助,我不知道我是否正在使用错误的获取。

您需要启用JavaScript才能运行此应用程序

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
这意味着您的浏览器不允许运行任何
Javascript

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
要在
Chrome
上无法
Javascript
,您可以这样做(如果您正在使用另一个浏览器,请在
Google
上执行serach操作,如何在该特定浏览器上无法
Javascript

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.

另一件事是,不要直接操纵
DOM
,比如

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
document.querySelector('.Pais').innerHTML = body;
相反,您可以让一个变量处于状态

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
state={body:''}
您可以使用
设置状态

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
componentDidMount(){
    fetch('/PaisForm')
    .then(function(response) {
      return response.text();
    })
    .then(function(body) {
      this.setState({body});
    });
  }
您可以从状态中渲染数据

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
<div className= "Pais">
    {this.state.body}
</div>
只需将该组件添加到您想要的任何位置

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
<div className= "Pais">
    <PaisForm />
</div>

您需要启用JavaScript才能运行此应用程序

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
这意味着您的浏览器不允许运行任何
Javascript

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
要在
Chrome
上无法
Javascript
,您可以这样做(如果您正在使用另一个浏览器,请在
Google
上执行serach操作,如何在该特定浏览器上无法
Javascript

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.

另一件事是,不要直接操纵
DOM
,比如

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
document.querySelector('.Pais').innerHTML = body;
相反,您可以让一个变量处于状态

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
state={body:''}
您可以使用
设置状态

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
componentDidMount(){
    fetch('/PaisForm')
    .then(function(response) {
      return response.text();
    })
    .then(function(body) {
      this.setState({body});
    });
  }
您可以从状态中渲染数据

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
<div className= "Pais">
    {this.state.body}
</div>
只需将该组件添加到您想要的任何位置

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
<div className= "Pais">
    <PaisForm />
</div>

在react组件中包含另一个组件的方法如下

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
组件的前n个顶部

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
import PaisForm from './PaisForm' //path to file
// your code
<div>
    // use your component
    <PaisForm />
</div>
然后在组件中

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
import PaisForm from './PaisForm' //path to file
// your code
<div>
    // use your component
    <PaisForm />
</div>

希望这有帮助。

在react组件中包含另一个组件的方法如下

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
组件的前n个顶部

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
import PaisForm from './PaisForm' //path to file
// your code
<div>
    // use your component
    <PaisForm />
</div>
然后在组件中

  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.
import PaisForm from './PaisForm' //path to file
// your code
<div>
    // use your component
    <PaisForm />
</div>


希望这能有所帮助。

PaisForm文件中有什么?一个表单也在reactjs中创建了一个输入。因此,您的错误可能是由于呈现页面的方式(服务器端逻辑)造成的。我们需要更多地了解您的代码,以提供实现这一目标的方向。但是,我确实想指出,以componenetDidMount()方法中的方式直接操作DOM不是最佳实践。最好将body的值设置为state,并使.Pais的body为{this.state.body}或您选择的任何状态。这样,您还可以显示一个加载指示器或其他东西,向用户显示它正在别处获取信息。@Carlos Deseda请看我的答案,希望能有所帮助。
PaisForm
文件中有什么内容?一个在reactjs中创建的带有一个输入的表单。因此,您的错误可能是由呈现页面的方式(服务器端逻辑)引起的。我们需要更多地了解您的代码,以提供实现这一目标的方向。但是,我确实想指出,以componenetDidMount()方法中的方式直接操作DOM不是最佳实践。最好将body的值设置为state,并使.Pais的body为{this.state.body}或您选择的任何状态。这样,你也可以显示一个加载指示器或其他东西,向用户显示它在别处获取信息。@Carlos Deseda请看我的答案,希望能有所帮助。我正在尝试处理加载。类似于jquery的加载:$(“.Pais”).load(“PaisForm”);你能解释一下你想要完成什么和为什么吗?我想用一个模态,在模态中显示组件。类似于但url,因为我想重复使用此模式来显示我的所有表单。这不是react打算使用的方式(我甚至不确定是否可能),将组件与另一个组件一起使用的方式是我向您展示的方式。@Carlosdesda如果您想重复使用此模式,您可以将您的
PaisForm
组件作为道具传递。我正在尝试加载。类似于jquery的加载:$(“.Pais”).load(“PaisForm”);你能解释一下你想要完成什么和为什么吗?我想用一个模态,在模态中显示组件。类似于但url,因为我想重复使用此模式来显示我的所有表单。这不是react打算使用的方式(我甚至不确定是否可能),将组件与另一个组件一起使用的方式是我向您展示的方式。@Carlosdesda如果您想重复使用此模式,您可以将您的
PaisForm
组件作为道具传递。
  You can add webfonts, meta tags, or analytics to this file.
  The build step will place the bundled scripts into the <body> tag.

  To begin the development, run `npm start` or `yarn start`.
  To create a production bundle, use `npm run build` or `yarn build`.