Getting API response in Postman but not in Ionic app browser view


#1

My code

    public function getbrands(Request $request)
    {
    
       $brands = Product::where('product',$request->product)->with('brands')->get();
     
        // $brands->where('product', 0);
       return $this->showAll($brands);
       // return response()->json(['message' => 'success','data' => $brands, 'success' => true], 200);
       // return response()->json($brands);
    }
    getBrands(pro) {
        return new Promise((resolve, reject) => {
           let headers = new Headers();
           headers.append('Content-Type', 'application/json');
           this.http.post(apiUrl+'getbrands', JSON.stringify(pro), {headers: headers}) 
            .subscribe
            (res => {
              resolve(res.json());
              }, 
            (err) => {
              reject(err);

           });
        });
    }
       getBrands() {
           console.log('getBrands Run');
           this.showLoader();
           var pro = localStorage.getItem('product');
           this.formData.getBrands(pro).then((result) => {
           this.loading.dismiss();
           this.data = result;
           // this.providers = result;
           console.log(this.data);
           console.log(this.data.length);
           console.log(this.data.data.length);
           console.log(this.data.data); // giver array of objects[{},{}]
           if (this.data.length > 0) {
      
              this.presentToast('Congratulations we have service in your City.');
           }else{
            this.presentToast('No service for this product.');
           }
         }, (error) => {
           this.loading.dismiss();
           console.log(error);
           this.presentToast('Invalid Request');
         });
       }

Getting data in postman but not in ionic app in browser


#2

Does the Ionic app send a correct request to your serveR? Check the network panel.


#3

Maybe this could help you?