@balrawi wrote:
Hello, all. I'm pretty new to Ionic, and one of my first major projects is sending an receiving data to/from a server located in my house.
http.get works completely fine, however, the http post yields an error.
Here's the relevant code:
ionViewDidLoad() {
console.log('ionViewDidLoad SensorData');
let headers = new Headers();
headers.append('Content-Type', 'text/plain');
let body = '{"ID":"3","ITEM":"blah","STATUS":"0","CREATED_AT":"2016-07-21"}';
this.http.post('/sidemenu/www/ajax/updateItem.php/', JSON.parse(JSON.stringify(body)), {headers: headers}).map(res => res.json()).subscribe(data1 => {
console.log(data1);
});
}
(There doesn't seem to be a way to format code, but if there is I'll change it immediately)Error:
Runtime Error
Unexpected end of JSON input
SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at Response.Body.json (http://localhost:8100/build/main.js:47836:25)
at MapSubscriber.project (http://localhost:8100/build/main.js:61365:150)
at MapSubscriber._next (http://localhost:8100/build/main.js:46705:35)
at MapSubscriber.Subscriber.next (http://localhost:8100/build/main.js:15865:18)
at XMLHttpRequest.onLoad (http://localhost:8100/build/main.js:48245:38)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9172)
at Object.onInvokeTask (http://localhost:8100/build/main.js:4613:37)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9093)
at r.runTask (http://localhost:8100/build/polyfills.js:3:4349)Ionic Framework: 3.2.1
Ionic App Scripts: 1.3.7
Angular Core: 4.1.0
Angular Compiler CLI: 4.1.0
Node: 6.9.2
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36Thanks guys. And I'm sorry about the formatting, I tried looking around for anything that'd help but there doesn't seem support for that here.
Posts: 1
Participants: 1