使用axios错误从express检索数据

时间:2019-03-17 20:47:18

标签: reactjs express

从express获取数据但无法正常工作无法获取数据。它一直给我一个错误,我在前端使用了sequilize ORM和axios。我尝试使用fetch而不是axio,但它给了我同样的错误。新的反应和表达方式

  

错误:网络错误       在createError(createError.js:17)       在XMLHttpRequest.handleError(xhr.js:87)

     

xhr.js:173 GET http://localhost:6000/students/class net :: ERR_UNSAFE_PORT

import React, { Component } from "react";
import axios from "axios";
import SearchCourse from "./SearchCourse";
import CourseItem from "./CourseItem";

class SearchHelper extends Component {
  constructor(props) {
    super(props);
    this.state = {
      class: []
    };
    this.searchClass = this.searchClass.bind(this);
  }
  componentDidMount() {
    console.log("Component Did Mount of Class Main");
    axios
      .get("http://localhost:6000/students/class")
      .then(res => {
        this.setState({
          class: res.data
        });
      })
      .catch(err => {
        console.log(err);
      })

}

index.js

router.get("/class", function(req, res) {
  console.log("Inside Course GET");
  Course.findAll({}).then(course => {
    res.send(course);
  });

});

0 个答案:

没有答案