Php api calling with ionic not access cookies?


#1

0
down vote
favorite
Hi Anyone please help me I developed one ts script in ionic framework. In this script i am calling one php file using get method.

URL working fine in POSTMAN if i enable postman interceptor and getting response. But if i disable postman interceptor i am not getting response.

Same URL i am calling in ionic ts script but i am not getting response.

Actually that php file using cookies. That is in different domain. I am calling that url from localhost. here is the js script code

import { Component, Injectable } from '@angular/core';
import { Http, Headers, XHRBackend, Request, RequestOptions, RequestOptionsArgs, Response } from '@angular/http';
import { NavController, NavParams } from 'ionic-angular';
import { HttpService } from '../../services/httpService';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';
@Component({
  templateUrl: 'chatList.html',
})
export class ChatDetailsPage {
  item;

  constructor(params: NavParams) {
    this.item = params.data.item;
  }
}

@Component({
  template: `
<ion-header>
  <ion-navbar>
    <ion-title>Chat - Online Members</ion-title>
  </ion-navbar>
</ion-header>
<ion-content>
  <ion-list>
    <button ion-item *ngFor="let item of items" (click)="openNavDetailsPage(item)" icon-start>
      <ion-icon [name]="'logo-' + item.icon" [ngStyle]="{'color': item.color}" item-start></ion-icon>
      {{ item.title }}
    </button>
  </ion-list>
</ion-content>
`
})
@Injectable()
export class ChatHomePage {
  items = [];

  constructor(public nav: NavController, private http: HttpService) {
    //let body = JSON.stringify({buddylist:1,initialize:1,EnableWebpImage:1,AppType:10});
    let headers = new Headers();    
    headers.append('Content-Type', 'application/json; charset=utf-8');    
    headers.append('Accept', '*/*');    
    //headers.append("Access-Control-Allow-Credentials", "true");
    /*headers.append('Upgrade-Insecure-Requests','1');
    headers.append('withCredentials','true');   
    headers.append("Access-Control-Allow-Origin","http://localhost:8100");
    headers.append("Access-Control-Allow-Credentials", "true");
    headers.append("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    headers.append("Access-Control-Allow-Headers", "Content-Type,Authorization,Upgrade-Insecure-Requests");
    */
    var Url = 'https://xxxxxxxx.com/cbschat/cbsonlineusers.php';        

    var Shortlist,Contacted,Preferred;   
    var Options = new RequestOptions({params:{buddylist:1,initialize:1,EnableWebpImage:1,AppType:10},headers:headers});
    this.http.get(Url, Options).map(res => res.json()).subscribe(
        data =>{
          console.log(data);
        },
        err => {
          console.log(err);
          console.log("Oops!");
        }
    );
    this.items = [
      {
        'title': 'Shortlisted Members',
        'icon': 'contact',
        'description': 'Shortlisted members available to chat',
        'color': '#0CA9EA'
      },
      { 
        'title': 'Contacted Members',
        'icon': 'contacts',
        'description': 'Contacted members available to chat',
        'color': '#F46529'
      },
      {
        'title': 'Preferred Members',
        'icon': 'javascript',
        'description': 'Preferred members available to chat',
        'color': '#FFD439'
      },           
    ]
  }
  openNavDetailsPage(item) {
    this.nav.push(ChatDetailsPage, { item: item });
  }

}

#2

Already checked your PHP error log?

Same URL i am calling in ionic ts script but i am not getting response.

No response in your console for?

data =>{
      console.log(data);
    },
    err => {
      console.log(err);
      console.log("Oops!");
    }

#3

i am getting empty json object


#4

Please edit your post, it is not very readable at the moment.
Use the </> button above the input field to format your code, command line output or error message (select the text first, then click the button or wrap it in ``` manually). Check the preview if it looks better. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.

Copy/pasting a post from Stackoverflow without fixing the formatting (and deleting stuff you copied from the site) is a bit impolite.