Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49083

PHP connection doesn't work on device

$
0
0

Hello everyone,
i’m new and i am just trying out a bit with ionic. I tried to make a HTTP Request to a testpage, but it doesn’t work if I test it on the device. Testing in browser it works fine.

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {

  constructor(private http: HttpClient) { }

  ngOnInit() {
  }

  login() {
    this.http.get('http://192.168.178.30/test/test.php')
      .subscribe(data => {
        var loginAccepted = data;
        console.log(loginAccepted);
        (<HTMLInputElement>document.getElementById("wrongPassword")).innerHTML = JSON.stringify(loginAccepted);
      });

  }

}
<?php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

$test = array(
  'msg'    =>  'Hello World.'
);
echo json_encode($test);
?>

This is how it looks in the browser.
test
If I run it on my device (Huawei P30 Pro) the text does not appear.

Edit: if I try it with https://demo0783833.mockable.io/ from mockable.io it works on my device

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 49083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>