Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70921

Failed to load http://localhost/api/index.php: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. core.js:1673 ERROR HttpErrorResponse {headers: HttpHeaders, status

$
0
0

@asha4640 wrote:

testing custom api – C:\xampp\htdocs\api\index.php

<?php $mysqli = new mysqli("localhost", "root", "", "test"); $query = "SELECT * FROM content_information"; $dbresult = $mysqli->query($query); while($row = $dbresult->fetch_array(MYSQLI_ASSOC)){ $data[] = array( 'name' => $row['title'] ); } if($dbresult){ $result = "{'success':true, 'data':" . json_encode($data) . "}"; } else { $result = "{'success':false}"; } echo $result; ?>

ionic projec t-- C:\xampp\htdocs\test_ionic\sparkTest
home.page.ts

import { Component } from ‘@angular/core’;
import { Router } from ‘@angular/router’;
import { HttpClient } from ‘@angular/common/http’;
import { Observable } from ‘rxjs’;

@Component({
selector: ‘app-home’,
templateUrl: ‘home.page.html’,
styleUrls: [‘home.page.scss’],
})
export class HomePage {

films: Observable;

constructor(private router: Router, private http: HttpClient) { }

ngOnInit() {
this.films =this.http.get(‘http://localhost/api/index.php’);
this.films.subscribe(data => {
console.log('my data: ', data);
});

}

}

home.page.html

<ion-header>

<ion-toolbar>

<ion-buttons slot=“start”>

<ion-menu-button></ion-menu-button>

</ion-buttons>

<ion-title>

Home

</ion-title>

</ion-toolbar>

</ion-header>

<ion-content padding>

{{ films.title }}

</ion-content>

I need to display the title from the database to the ionic home page. but my console showing the below error

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70921

Trending Articles



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