As far as i know, the Angular class Http can be used for any HTTP Requests. If i want to GET any data, i just have to use following code.
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {Http} from "@angular/http";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, public http: Http) {
let url = 'http://some.url.com/';
this.http.get(url)
.subscribe(response => {
console.log(response)
}, xhr => {
console.log(xhr);
});
}
}
Nearly the same for a POST Request:
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {Http} from "@angular/http";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, public http: Http) {
let url = 'http://some.url.com/'
this.http.post(url, {data: 'data'})
.subscribe(response => {
console.log(response)
}, xhr => {
console.log(xhr);
});
}
}
In both cases, there is an OPTIONS Pre-Flight Request. So my first question is: How can i disable the Pre-Flight OPTIONS Request? i really need to do that, so please do not just answer like: it is not possible or it this Request needs to be done…
The other thing is, when i send a PUT or a DELETE Request, PHP will not recognize it as PUT or DELETE. Why does PHP not recognize a Angular HTTP PUT or DELETE?
Please answer like you will talk to a complete noob. I need to explain it to my work collegues (and i need to convince the to use Ionic in combination with a RESTful PHP API)
Kind regards