Hello evryone ! i tried using the api with xml data.. (ionic 3 & angular 5)


#1

null:1 GET http://localhost:8100/null 404 (Not Found)

client-service.ts:17 Hello clientServiceProvider Provider
clientpage.ts:74 PeopleListPage constructor.
clientpage.ts:99 ionViewDidLoad PeopleListPage
polyfills.js:3 POST http://avocanet.tn/api/WSClient/Get?AvocatId=1007 405 (Method Not Allowed)
*******API
http://avocanet.tn/api/WSClient/Get?AvocatId=1007
client.html



<ion-item *ngFor=“let item of items” ion-item (click)=" detailClient()">

    <button ion-button outline item-end icon-left clear>
      <ion-icon right name="arrow-dropright"></ion-icon>
    </button>
    <button ion-item>
        <ion-icon  style="color:midnightblue" name="contact" item-start></ion-icon>
        <h2>  {{ item.Client }}</h2>
      </button>
      <button ion-item>
        <ion-icon style="color:midnightblue" name="pin" item-start></ion-icon>
        <h2> {{ item.Client }}</h2>
      </button>
   
  </ion-item>

client.ts*******

loadPeople(){
this. clientServiceProvider.loadXML(this.id).then((result) => {

  // this.loading.dismiss();
   //alert(JSON.stringify(data));
   this.clientitem[0]= result;
   localStorage.setItem('token',this.clientitem[0].access_token);
   console.log(result);
 

 }, error => {
  // this.loading.dismiss();
  // this.presentToast(error);
  this.showErrorserver();
 });

}

ionViewDidLoad() {
console.log(‘ionViewDidLoad PeopleListPage’);
}

//
showErrorserver() {
//this.loading.dismiss();
let alert = this.alertCtrl.create({
title: ‘Ereur’,
subTitle: ‘Erreur serveur’,
buttons: [
{
text: ‘Ok’,
role: ‘Ok’,
handler: data => {
}
}]
});
alert.present(prompt);
}
**************************client-service.ts
loadXML(credentials) {

return new Promise((resolve, reject) => {
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');

    this.http.post(apiUrl, JSON.stringify(credentials), {headers: headers})
      .subscribe(res => {
        resolve(res.json());
      }, (err) => {
        reject(err);
      });
});

}

public clientdata(id){

//alert(UserName + Password)
const apiUrl = 'http://avocanet.tn/api/WSClient/Get?AvocatId='+id;
 
 return new Promise(resolve => {
   this.http.get(apiUrl)

   .subscribe(data => {
    
     var resultt = data.json();
     //console.log('api result '+resultt.toString());   
     resolve(resultt);
     //console.log('api'+resultt);   
   }, err => {
     console.log(err);
     resolve(null);
   })
  });

}


#2

Don’t manually instantiate Promises. You say you are dealing with XML data, but all your code says it is expecting JSON. That’s never going to work.


#3

thanks… :slight_smile: