Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49224

Error during POST request in ionic 2

$
0
0

@Sidharth_1999 wrote:

I’m trying to make a POST request to a server I’ve created. But when I run the application, I get the error :
" Unexpected token L in JSON at position 0"

This is the code I’m using:

import { Http, Headers} from '@angular/http';
import 'rxjs/add/operator/map';

export class MyClass {
constructor(public http : Http){

let headers = new Headers();
headers.append('Content-Type', 'application/json');

let body = {
   message : "Do you hear me?"
};
this.http.post('https://myserverurl', JSON.stringify(body), {headers:headers})
  .map(res=>res.json())
  .subscribe((data)=>{
  console.log(data);
  });
 }
}

Appreciate any help anyone has to offer. Thanks !

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 49224

Trending Articles



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