遇到此错误
代码: Post_providers.ts
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class PostProviders {
server: string = "http://localhost/server_api/"
constructor(public http: Http){
}
postData(body, file){
let type = "application/json; charset=UTF-8";
let headers = new Headers ({'Content-type': type});
let options = new RequestOptions({headers: headers});
return this.http.post(this.server + file, JSON.stringify(body), options)
.map(res => res.json());
}
}
file_aksi.php
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class PostProviders {
server: string = "http://localhost/server_api/"
constructor(public http: Http){
}
postData(body, file){
let type = "application/json; charset=UTF-8";
let headers = new Headers ({'Content-type': type});
let options = new RequestOptions({headers: headers});
return this.http.post(this.server + file, JSON.stringify(body), options)
.map(res => res.json());
}
}
config.php
define('Db_name', 'ionic_app');
define('Db_user', 'root');
define('Db_password', '');
define('Db_host', 'localhost');
$mysqli = new mysqli(Db_name, Db_host, Db_password, Db_user);
我仍在尝试解决此问题,但仍然没有运气。我正在努力解决最近两天以来的错误,但是我不明白我做错了什么。
Farrukh iftikhar在评论中写的错误:
core.js:1448 ERROR SyntaxError:
Unexpected token d in JSON at position 0
at JSON.parse (<anonymous>)
at Response.Body.json (http.js:1091)
at MapSubscriber.project (post_providers.ts:20)
at MapSubscriber._next (map.js:79)
at MapSubscriber.Subscriber.next (Subscriber.js:89)
at XMLHttpRequest.onLoad (http.js:1591)
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.js:4740)
at t.invokeTask (polyfills.js:3) at r.runTask (polyfills.js:3)