Hi, I’m using the barcodescanner plugin. I want to use the value data.text to send it via HTTP and I want to recover the value (php script) and display it in my page. Can you help me ?
app.module.ts :
import { HTTP } from ‘@ionic-native/http/ngx’;
providers: [
StatusBar,
SplashScreen,
BarcodeScanner,
HTTP,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
page.home.ts
import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import { BarcodeScanner } from ‘@ionic-native/barcode-scanner’;
import { HTTP } from ‘@ionic-native/http/ngx’;
@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {
// store the scanned result
num: string;
constructor(public navCtrl: NavController, private barcodeScanner: BarcodeScanner, private http: HTTP) {
}
scan() {
this.barcodeScanner.scan().then(data => {
// this is called when a barcode is found
this.num = data.text;
this.http.get('https://www.mywebsite.com/barcode_verif.php?barrecode='+this.num, {}, {})
.then(data => {
//JSON.parse(data.data);
console.log('DATAS '+data.data); // data received by server
this.post_data = data.data;
})
.catch(error => {
console.log(error.status);
console.log(error.error); // error message as string
console.log(error.headers);
});
});
}
}
page.home.html
Ionic Blank
<ion-item>
<ion-label fixed>Number</ion-label>
<ion-input type="text" value="" [(ngModel)]="num"></ion-input>
<ion-input type="text" value="" [(ngModel)]="post_data"></ion-input>
</ion-item>
<ion-item>
<button ion-button (click)="scan()">Button</button>
</ion-item>
Best regards