sabbir sabbir - 2 years ago 2535
AngularJS Question

angular ajax: Unexpected token I in JSON at position 0

I'm trying to sent

http post request
. But when I'm trying to make
request, I've got the following error:

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)

My code (angular) is given below:

$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);


How can I solve this problem? Thanks in Advance

Answer Source

SyntaxError: Unexpected token I in JSON at position 0 means that the server response isn't valid JSON, open the network tab in your console and check the response of the request to see what's wrong.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download