Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70439

Http.post posts data twice, why?

$
0
0

@travBrad wrote:

Hi there,

I’ve used the code below to save an object called position to a locally hosted json-server. Now I can successfully post to the array but every time that the post method is called, the data is saved twice causing duplicate entries. How do I prevent the duplicate entries?

saveToServer(pos) {
    this.position = pos;
    console.log("sendPosToServer" + JSON.stringify(this.position));
    var headers = new Headers();
    headers.append("Accept", 'application/json');
    headers.append('Content-Type', 'application/json');
    let options = new RequestOptions({ headers: headers});
    console.log("post params " + JSON.stringify(this.position));

    console.log("complete position, save");

    /*
    this.http.post(baseURL + 'positions', this.position, options)
              .map(res => console.log("first"))
              .share();
    */

      this.http.post(baseURL + 'positions', this.position, options)
        .subscribe(data => {
          console.log("First spot " + data['_body']);
        }, error => {
          console.log(error);
        });
    console.log("bottom of sendPosToServer");
  }

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70439

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>