Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不从Angular调用PHP文件_Angular_Typescript_Ionic Framework_Ionic2_Ionic3 - Fatal编程技术网

不从Angular调用PHP文件

不从Angular调用PHP文件,angular,typescript,ionic-framework,ionic2,ionic3,Angular,Typescript,Ionic Framework,Ionic2,Ionic3,要求:我有一个php文件,它从MySQL生成Excel数据。我想从我的表格中调用它 问题:当我从HTML调用它时,它会正常下载,没有任何问题,但当我从Angular调用它时,它不会被下载 首先,我向您展示我下面的download.html <html> <head> <body> <form action="exportData.php" method="get"> <button type="submit">Submit<

要求:我有一个php文件,它从MySQL生成Excel数据。我想从我的表格中调用它

问题:当我从HTML调用它时,它会正常下载,没有任何问题,但当我从Angular调用它时,它不会被下载

首先,我向您展示我下面的
download.html

<html>
<head>
<body>

<form action="exportData.php" method="get">
  <button type="submit">Submit</button>
</form>

</body>
</head>
</html>
<ion-header>
  <ion-navbar>
      <button ion-button menuToggle>
          <ion-icon name="menu"></ion-icon>
        </button>
    <ion-title>View Complaint Open / Close</ion-title>
    <ion-buttons end>
      <button ion-button (click)="showdata()">{{c_status}}</button>
      <button ion-button icon-only  (click)="downldexcl()" type="submit" title="Download Excel File">
        <ion-icon  name="ios-download-outline" class="top-icon"></ion-icon>
        </button>
    </ion-buttons>
  </ion-navbar>
</ion-header>
home.ts

import { UserProvider } from '../../providers/user/user';

...//some code 
  downldexcl()
{
  this.user.exlDwnld().subscribe(datac => {
      console.log(datac,"list");
      console.log(datac);
      //document.location.href = this.user._url+"download.php?file="+datac;
    });
}
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Http,Response,Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import {LoadingController, ToastController, ModalController, AlertController} from "ionic-angular";

...//some code 
    exlDwnld()
      {
       // let params1_c = '&t1label=' + t1label+'&t1data=' +encodeURIComponent(t1data)+'&h1colnum=' + h1colnum+'&t2label=' + t2label+'&t2data=' + encodeURIComponent(t2data)+'&h2colnum=' + h2colnum+'&total1=' + total1+'&total2=' + total2+'&fromdt=' + fromdt+'&todt=' + todt+'&filename=' + filename+'&topheader=' + topheader+'&subheader1=' + subhead1+'&subheader2=' + subhead2;
        var headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        return this._http.post(this._url + "exportData.php", {headers: headers})
          .map((response: Response) => response.json());
      }
user.ts

import { UserProvider } from '../../providers/user/user';

...//some code 
  downldexcl()
{
  this.user.exlDwnld().subscribe(datac => {
      console.log(datac,"list");
      console.log(datac);
      //document.location.href = this.user._url+"download.php?file="+datac;
    });
}
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Http,Response,Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import {LoadingController, ToastController, ModalController, AlertController} from "ionic-angular";

...//some code 
    exlDwnld()
      {
       // let params1_c = '&t1label=' + t1label+'&t1data=' +encodeURIComponent(t1data)+'&h1colnum=' + h1colnum+'&t2label=' + t2label+'&t2data=' + encodeURIComponent(t2data)+'&h2colnum=' + h2colnum+'&total1=' + total1+'&total2=' + total2+'&fromdt=' + fromdt+'&todt=' + todt+'&filename=' + filename+'&topheader=' + topheader+'&subheader1=' + subhead1+'&subheader2=' + subhead2;
        var headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        return this._http.post(this._url + "exportData.php", {headers: headers})
          .map((response: Response) => response.json());
      }

为什么在Ionic/Angular页面中单击按钮时,Excel无法下载。

您在Angular中使用的是post请求方法,而不是get。试着改变一下

return this._http.post(this._url + "exportData.php", {headers: headers})

这应该能奏效

此外,如果您正在使用旧的http模块,请从“@angular/common/http”导入新的HttpClientModule


然后删除映射到response.json,新模块会为您这样做。

您的控制台记录的是什么
datac
?它显示的是数据,从屏幕截图上看,它看起来像是
exportData。php
正在返回原始tsv数据?您可能不想将其映射到json,您需要在响应中实际使用它。如果您希望它的行为与基本html示例类似,您可以使用类似于
window.open(this.\u url+“exportData.php?”+params)
-这应该像html示例中的表单submit那样直接打开php文件,但excel仍然没有下载,见我的回复-,我们也安装了新的HttpClientModule,更新了我的问题,请让我知道下一步该怎么做