mercredi 24 mai 2017

How can i call my id from my api to reactjs

See Im having a problem im using add in ajax

  handleSubmit(name, address,department){

 const laman = {
      'Employee_Name': name,
      'Address': address,
      'Department': department

    }
    return fetch('http://localhost:5118/api/employeedetails/PostEmployeeDetail?', {
        method: 'POST',
        headers: {
        'Content-Type': 'application/json'
        },
        body: JSON.stringify(laman)
    })
    .then(function(response) {
      console.log(response)

      return response.json();
    })
    .then((result)=> {
       var jsonReturnedValue = [...this.state.jsonReturnedValue];
       jsonReturnedValue.push(laman);
       this.setState({jsonReturnedValue})
       this.refs.Name.value="";
       this.refs.Address.value="";
       this.refs.Department.value="";
       // this.setState({ value: '' });
    })
    .catch(function(error) {
      console.log(error);

    })

but when it add new row it dont have an id because of it dont know what id to put.... but when i refresh it already had an id because it was added on the database and it was autoincreament in my sql.. id why here's a picturehere is the image

enter image description here




Aucun commentaire:

Enregistrer un commentaire