Insert data with rest api


#1

Hi
I’m using laravel for back-end all api is work on postman tool,
i want to insert some data using ionic form but i face kind of errors , i don;t understand what is it,
can anybody help me…

(upload://wwadSwjESBnkZtTCqs9DnlrIpGn.PNG)

this is my provider code

addUser(data) {
return new Promise((resolve, reject) => {

  var headers = new Headers();
  headers.append("Accept", "application/json");
  headers.append("Content-Type", "application/json");
  // let options = {headers: headers};

  this.http.post('http://127.0.0.1:8000/api/posts', JSON.stringify(data), {headers: headers})
    .subscribe(res => {
      // resolve(res.data);
      console.log(res);
    }, (err) => {
      reject(err);
    });
});

}

this is my typescript code

post = { title: ‘’, body: ‘’};
data: any;

constructor(public navCtrl: NavController, public myhttp: PostProvider, public http:HttpClient) {}

dosubmit() {
this.myhttp.addUser(this.post)
.then((result) => {
console.log(result);
}, (err) => {
console.log(err);
});
}

this is my html code

<form (ngSubmit)="dosubmit()">

    <ion-item>
      <ion-label floating>Title</ion-label>
      <ion-input type="text" [(ngModel)]="post.title" name="title"></ion-input>
    </ion-item>

    <ion-item>
      <ion-label floating>Description</ion-label>
      <ion-input type="text" [(ngModel)]="post.body" name="body"></ion-input>
    </ion-item>

    <ion-item>
      <button ion-button type="submit" block>Add User</button>
    </ion-item>

</form>

==============

plz help me


#2

Your server seems to respond with an error message about missing data. Did your app actually send data to the server? You should be able to see this in the dev tools as well.