错误:[$ http:badreq] Http请求配置url必须是一个字符串。收到:{}

时间:2017-07-17 18:09:15

标签: javascript angularjs

我将角度升级到1.5,我收到此错误。这是我的控制器里面的代码

var reportURL = $rootScope.hostUrl + API_VERSION + "/runreports/" +
                encodeURIComponent(scope.reportName);
reportURL += "?output-type=" + 
             encodeURIComponent(scope.formData.outputType) + 
             "&tenantIdentifier=" + $rootScope.tenantIdentifier + 
             "&locale=" + scope.optlang.code + "&dateFormat=" + scope.df;

var inQueryParameters = buildReportParms();
if (inQueryParameters > "") reportURL += "&" + inQueryParameters;

// Allow untrusted urls for the ajax request.

reportURL = $sce.trustAsResourceUrl(reportURL);
http.get(reportURL, {responseType: 'arraybuffer'}).
  success(function(data, status, headers, config) {
    var contentType = headers('Content-Type');
    var file = new Blob([data], {type: contentType});
    var fileContent = URL.createObjectURL(file);

    // Pass the form data to the iframe as a data url.
    scope.baseURL = $sce.trustAsResourceUrl(fileContent);
  });

自Angular 1.4.9起,$ http服务只接受纯字符串作为URL。如果我传入一个具有toString()方法的对象,$ http会引发异常

此代码的解决方法是什么?

0 个答案:

没有答案