1

I am struggling with following error since last 2 hours. I dont know whats wrong.

SyntaxError: Unexpected end of input
at eval (<anonymous>)
at Function.globalEval (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:4:4228)
at init.domManip (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:5:20866)
at init.append (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:5:18502)
at init.<anonymous> (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:5:19874)
at Function.access (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:4:5765)
at init.html (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:5:19537)
at Object.<anonymous> (http://127.0.0.1:8887/js/angular-ui-router.min.js:7:24156)
at https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js:16:71
at ta (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js:84:35) <div ui-view="" class="ng-scope">

I could only find that this occurs when i call an angjs service

    app.factory("Userservice", ['$rootScope', '$http', 'GENERAL_CONFIG', 'FlashService',
    function($rootScope, $http, GENERAL_CONFIG, FlashService) {
        return {
            FindUserDetail: function(userid) {
                return $http.get(String.format('{0}/GetUserDetailById?UserId={1}',
                    GENERAL_CONFIG.ServiceWebApiUrl,
                    userid));
            }
        };
    }
]);

Following is my controller code

    var userId = loggedIn.userId;
            Userservice.FindUserDetail(userId).then(//this line throws error
                function(data) {
                    if (data.data != null || data.data != undefined) {
                      var a = data.data.myJsonVariable //I get valid data here
                    }
                },
                function(httperror) {
                    FlashService.Error("Error Status Is " + httperror.status, true);
                });

Unexpected end of input is very generic error. Guide me.

6
  • It appears to be throwing when jquery is parsing the response of your call to GetUserDetailById. It is probably returning an incomplete or invalid json string. Can you edit to add in the response coming from the server for this call? Commented Jan 9, 2017 at 17:10
  • The json response is complete. When I parse the response in json editor, its complete. Parsed without any errors. Even inside the success function i can access the json object. Like data.data.myJsonVariable Commented Jan 9, 2017 at 17:14
  • are you calling this as soon as this page/controller is instantiated? or is this returned in some function? Commented Jan 9, 2017 at 17:22
  • 2
    Where are you getting String.format from ? Have you extended the prototype? Commented Jan 9, 2017 at 17:35
  • If you want help with this error, you'll need to provide the JSON from the response, as it is shown in the Network tab of the browser's Developer Tools. Feel free to edit out confidential information, of course. However, the error is referring to the problem indicated by @Rhumborl. Without that information we cannot "guide you". Commented Jan 9, 2017 at 18:15

2 Answers 2

1

I guess you are trying to form string based on variable value. Where you're trying to utilize String.Format function of C#. String.Format wouldn't be available inside JavaScript. Or might have missed to extend String prototype.

You could do use Template Literal of ES6 here

return {
 FindUserDetail: function(userid) {
   return $http.get(`${GENERAL_CONFIG.ServiceWebApiUrl}/GetUserDetailById?UserId=${userid}`);
 }
};
Sign up to request clarification or add additional context in comments.

Comments

0

Angularjs throws this exception if you use it for repeating elements and miss something on the HTML side.

In my case, <a href="javascript:void" class="btn yellow-crusta" ng-click="addItem()"> <i class="fa fa-plus"></i> </a> gave the exception.

Then I realized that I needed to end the element, just like it said.

So adding "; (semicolon)" to the end of and removing "void" from the href tag, as there was no function with the name "void" to call, did the job.

<a href="javascript:;" class="btn yellow-crusta" ng-click="addItem()"> <i class="fa fa-plus"></i> </a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.