springmvcとangularjsを使用してデータを読み込み、ウェブページに表示しています。 URLからデータを読み取るために私はJSoup APIを使用しています。スプリングコントローラから文字列を返してウェブページに表示することができません
URLから読み取ったコンテンツをWebページに表示しながらエラーが発生しました。何かアドバイスが参考になります。
コード:
HTML:
<div ng-controller="readContentController">
<div>
{{content}}
</div>
</div>
JSコード:
//controller
myApp.controller('readContentController', function ($rootScope, $scope, $sce, ReportService, $window) {
$scope.content = {};
MyService.getDataFromURL().then(
function (response) {
console.log("response :" + response);
$scope.content = response;
},
function (errResponse) {
$rootScope.showError("error :" + errResponse);
});
});
//service call
myServiceFactory.getDataFromURL = function(){
var deferred = $q.defer();
$http.get('/getHTMLDataFromURL')
.then(
function (response) {
deferred.resolve(response.data);
},
function(errResponse){
console.error('Error while fetching data' + errResponse);
deferred.reject(errResponse);
}
);
return deferred.promise;
}
スプリングコントローラ:
@RequestMapping(value = "/getHTMLDataFromURL", method = RequestMethod.GET)
public
@ResponseBody String getHtmlStrigContent() throws Exception {
Document doc = Jsoup.connect("https://xyz.abc.com/myFile.pdf").get();
String htmlString = doc.toString();
System.out.println("asD" + htmlString);
return htmlString;
}
エラーメッセージ:
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at Ec (angular.min.js:16)
at ic (angular.min.js:93)
at angular.min.js:93
at q (angular.min.js:7)
at od (angular.min.js:93)
at f (angular.min.js:95)
at angular.min.js:132
at m.$eval (angular.min.js:146)
at m.$digest (angular.min.js:143)
(anonymous) @ angular.min.js:119
myService.js:158 Error while fetching dataSyntaxError: Unexpected token < in JSON at position 0
他のWebページからコンテンツを読み込み、アプリケーションWebページに表示しようとしています。
これは動作していますが、htmlの出力を表示したいのですが、私はURLからhtmlコンテンツを読んでいます。ブラウザで開くと、Webページ(URLに当たったときに表示される同じページ) 。現在はStringとして表示されていますが、htmlの文字列表現ではなくWebページとして応答を表示できます。助言があれば助かります。 – sss
@sss:私の第2段落を見てください。 :) –
入力のおかげで@アルヴィントンプソン。それは働いた。 – sss