Yêu cầu thg 6 13, 2021 2:00 CH 155 0 1
  • 155 0 1
+1

em đang làm 1 bài về crud react js mongodb và bị lỗi net::ERR_SSL_PROTOCOL_ERROR khi sử dụng axios.delete em mò hoài mà không biết sửa như nào mong mọi người giúp em vói ạ em xin cảm ơn

Chia sẻ
  • 155 0 1
import React, { Component} from 'react';
import axios from "axios";
import {Link} from "react-router-dom";

export default class Persons extends Component{
    constructor(props){
        super(props);
        this.state ={
            allData:[],
            showData:[],
            soluong: 5,
            soluongnut:0,
        };
        this.select= React.createRef();
        
    }
    componentDidMount(){
        axios.get('http://localhost:8080/ds')
        .then((res)=>{
            this.setState({allData:res.data,
            showData: res.data.slice(0,this.state.soluong),
            soluongnut: Math.ceil(res.data.length/this.state.soluong),
           
            });
            console.log(res);
        })
        .catch((err)=>{
            console.log(err);
        });
    }

    taoDaySo=(number)=>{
        var arr=[];
        for(let i=1;i<=number;i++){
            arr.push(i);
        }
      

        

        return arr.map((element)=>{
            return(
                <div key={element}>
                    <button onClick={()=>{
                        this.chuyentrang(element);
                    }}>{element}</button>
                </div>
            )
        })
    };
    chuyentrang=(number)=>{
       var end= this.state.soluong*number;
        this.setState({showData:this.state.allData.slice(end-5,end)})

    }

    thaydoisoluong=()=>{
        this.setState({soluong: this.select.current.value,
        showData: this.state.allData.slice(0,this.select.current.value),
        soluongnut: Math.ceil(this.state.allData.length/this.select.current.value),
    });
    }

    deleteRow (id){  
        axios.delete(`https:localhost:8080/delete/${id}`)
             .then(res => {
                console.log(res);
                console.log(res.data);
             })
        }  
        

    render(){
       
        return (
            <div>
                    <h1 className="ds">Danh Sách Sinh Viên</h1>
                   <table className='table table-striped table-bordered'>
                            <thead > 
                            <tr>
                                <th >Tên</th>
                                <th >Tuổi</th>
                                <th >Lớp</th>
                                <th>Chức năng</th>
                            </tr>
                            </thead>
                            <tbody>
                            { this.state.showData.map((element)=>(
                            <tr>
                                    <td >{element.ten}</td>
                                    <td >{element.tuoi}</td>
                                    <td>{element.lop}</td>
                                    <td>
                                        <Link className="btn btn-primary" to={`/create/${element._id}`}>Sửa</Link>
                                        <Link className="btn btn-danger" onClick={() => this.deleteRow(element._id)}>Xóa</Link>
                                    </td>
                                    
                            </tr>
                    
                ))}
                </tbody>
                    </table>

                    <div className="dayso">{this.taoDaySo(this.state.soluongnut)}
                    <select ref={this.select} onChange={this.thaydoisoluong}>
                        <option value="5">5</option>
                        <option value="10">10</option>
                        <option value="15">15</option>
                    </select>
                 </div>
                
            </div> 
        )

        
    }
}

và đây là hàm delete của em

router.route('/delete/:id').delete((req, res, next) => {
    Person.findByIdAndRemove(req.params.id, (error, data) => {
      if (error) {
        return next(error);
      } else {
        res.status(200).json({
          msg: data
        })
      }
    })
  })

nhưng nó báo lỗi DELETE https://localhost:8080/delete/60c57490281afa298c46143e net::ERR_SSL_PROTOCOL_ERROR

1 CÂU TRẢ LỜI


Đã trả lời thg 6 14, 2021 2:08 SA
Đã được chấp nhận
0

đổi https thành http

Chia sẻ
Avatar lâm phong @lamphong
thg 7 9, 2021 12:00 CH

dạ em cảm ơn nhiều ạ hihi

thg 7 25, 2023 3:45 SA

Ui, được luôn nè. cảm ơn ạ

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí