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

Failed to execute 'open' on 'XMLHttpRequest' : invalid URL Ionic 3

$
0
0

@dery wrote:

Hi,
I'm new in ionic 3 , I try to make a login post to API,
here is my api provider

export class ApiProvider {

  private host_url : string = '//api.someapihost.com:8080/app_dev.php';

  constructor(private http: Http) {
  }

  postLogin(data){
    let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
    let options = new RequestOptions({ headers: headers });
    let urlSearchParams = new URLSearchParams();
    urlSearchParams.append('username', data.username);
    urlSearchParams.append('password', data.password);
    let body = urlSearchParams.toString()
    return this.http.post(this.host_url+'/login_check/', body, options)
        .map(this.extractData)
        .catch(this.handleErrorObservable);
  }


  private extractData(res: Response) {
    let body = res.json();
    return body || {};
  }
  private handleErrorObservable (error: Response | any) {
    console.error(error.message || error);
    return Observable.throw(error.message || error);
  }

and this is my login.ts

 doLogin(){
    let loader = this.loadingController.create({
      content: "Sign in ...."
    });
    loader.present();
    this.api.postLogin(this.loginForm.value).subscribe(
        data => {
          console.log(data)
          loader.dismiss()


  }

it's works fine on chrome but when I build in android device and try to test my login I got

Failed to execute 'open' on 'XMLHttpRequest' : invalid URL

when I debug on chrome inspect device console.
I also have installed whitelist plugin and have this meta-tag in my index.html
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

I try to figure out for hours, please help guys..

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



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