[英]angular ajax: Unexpected token I in JSON at position 0
我正在嘗試在http post request
發送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: Unexpected token I in JSON at position 0
意味着服務器響應無效JSON,打開控制台中的網絡選項卡並檢查請求的響應以查看錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.