SyntaxError:意外的令牌< ISON2 App

时间:2017-05-21 16:52:43

标签: php mysql json ionic2

我将数据注册到数据库。然后我想列出数据,但是我得到一个错误(SyntaxError:在位置0的JSON中出现意外的令牌<)我不明白我在哪里犯错误。

list.html

<ion-header>

 <ion-navbar>
   <ion-title>list</ion-title>
 </ion-navbar>

</ion-header>


<ion-content padding>

  <ion-list>
   <ion-item *ngFor="let isim of dataisim">{{isim}}</ion-item>
  </ion-list>

</ion-content>

list.ts

   import { Component } from '@angular/core';
   import { IonicPage, NavController, NavParams } from 'ionic-angular';
   import {ServiceProvider} from "../../providers/datamember";
   import { Http, Headers, Response, ResponseOptions } from '@angular/http';

   @IonicPage()
   @Component({
   selector: 'page-list',
    templateUrl: 'list.html',
   })
   export class ListPage {


   dataisim : any;

    constructor(public navCtrl: NavController, public navParams: 
     NavParams,public service:ServiceProvider,
        public http : Http) {
       }

   ionViewDidLoad() {
     console.log('ionViewDidLoad ListPage');

       this.service.getList().subscribe(data =>
         this.dataisim = data );
          console.log(this.dataisim);
  }
 }

service.ts

  import { Injectable } from '@angular/core';
  import { Http, Headers, Response, ResponseOptions } from '@angular/http';
  import { Observable } from 'rxjs/Observable';
  import 'rxjs/add/operator/map';
  import { Storage } from '@ionic/storage';

  @Injectable()
   export class ServiceProvider {
     public local : Storage;
     mydata : any;
     api : string = 'http://localhost:8080/ionic2_kaydet.php';
     api2 : string = 'http://localhost:8080/kaydet3.php';
     url : string = "http://localhost:8080/listele.php";

     constructor(public http: Http) {       
    }
      postLogin(data){
      console.log("api data:" + data);
      let headers = new Headers({ 'Content-Type' : 'application/x-www-form-
       urlencoded' });
          return this.http.post(this.api, data, {
              headers:headers,
              method:"POST",                  
        }).map(
              (res:Response) => {return res.json();}
        );
     }

   getList() {

      let headers = new Headers({ 'Content-Type' : 'application/x-www-form-
     urlencoded' });
        return this.http.get(this.url, {
              headers:headers,
              method:"GET",                  
        }).map(
              (res:Response) => {return res.json();}
        )
    }

  }

listele.php

  <?php

  header("Access-Control-Allow-Origin: *");

  $conn = new mysqli("localhost", "root", "", "ionic2");
   $data= array();
   $select = "select * from user2";
   $qr = $conn->query($select);
    while($row = $qr->fetch_assoc()){
      $data[]=$row;
   }
  print json_encode($data);
 ?>

0 个答案:

没有答案