微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – angular ajax:在位置0的JSON中出现意外的令牌

我正在尝试在http post请求中发送html作为json.但是,当我尝试生成$http.post请求时,我遇到以下错误

angular.js:12783 SyntaxError: Unexpected token I in JSON at position 0
    at Object.parse (native)
    at fromJson (http://localhost:9001/bower_components/angular/angular.js:1274:14)
    at defaultHttpResponseTransform (http://localhost:9001/bower_components/angular/angular.js:9703:16)
    at http://localhost:9001/bower_components/angular/angular.js:9794:12
    at forEach (http://localhost:9001/bower_components/angular/angular.js:341:20)
    at transformData (http://localhost:9001/bower_components/angular/angular.js:9793:3)
    at transformResponse (http://localhost:9001/bower_components/angular/angular.js:10582:21)
    at processQueue (http://localhost:9001/bower_components/angular/angular.js:15097:28)
    at http://localhost:9001/bower_components/angular/angular.js:15113:27
    at Scope.$eval (http://localhost:9001/bower_components/angular/angular.js:16359:28)

我的代码(角度)如下:

$scope.generate_pdf = function() {
    var html =  angular.element('html').html(); // get all html

    var service = API.getService();
    // JSON.stringify( { html:  html } this also cause same error
    service.downloadPdf({},{ html: html },function(res) {
        console.log("res : ",res);
      },function(err) {
        console.log("err : ",err);
      });


  };

我怎么解决这个问题?提前致谢

解决方法

SyntaxError:位于0的JSON中的意外令牌I意味着服务器响应无效JSON,打开控制台中的网络选项卡并检查请求的响应以查看错误.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐