I have an SPA that needs to support any language. Upon loading, it deploys all the labels in a default language. Within the HTML, these are included as:
:
<label ...>{{Labels.Username}}</label>
:
<label ...>{{Labels.Password}}</label>
:
(This is just an example, not the actual HTML).
Now, upon initial loading, all goes OK. When I attempt to change language (even to the initial default language) I get the following error:
SyntaxError: Unexpected token }
at Object.parse (native)
at pc (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:14:486)
at Xb (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:80:157)
at http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:81:70
at n (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:7:302)
at $c (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:81:52)
at c (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:82:235)
at http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:118:182
at m.$eval (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:132:221)
at m.$digest (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:129:233)(anonymous function) # angular.js:12116(anonymous function) # angular.js:8976(anonymous function) # angular.js:14355m.$eval # angular.js:15574m.$digest # angular.js:15385m.$apply # angular.js:15679l # angular.js:10166J # angular.js:10338w.onload # angular.js:10279
I attempted to debug this by setting breakpoints into my JavaScript code at every relevant location, but (as suggested by the error) the issue appears to be within the Angular code. I need to find our what triggers this.
Found the issue. It had to do with the fact that, under certain conditions, the JSON that was received (i.e. its string representation) from the remote server was wrongly formatted.
It took me some time to find this, and it looks to me reasonable to assume that I would reach this much faster had AngularJS provided more clear description of the error (this particular as well as others).
Thanks to those that sent comments and recommendations.
Related
I tried
const some_variable = require(['C:/Users/Admin/some_folder/something.json']);
const the_list_i_want_to_save_in = JSON.parse(some_variable);
And got the error
Unexpected token u in JSON at position 1
at JSON.parse (<anonymous>)
at <anonymous>:1:6
I searched here for similar questions and noticed that the u is because some_variable is "undefined". So how do I properly load in the json file and why is it undefined in this case? Never used requirejs before so I don't know how it works.
i am using wordpress rest api v2 for getting data from my working wordpress website to angularjs application. all is working fine but when i want to use post meta like "_ait-item_item-data". its return me an error "undefined".
i am using his code to get post meta :
$scope.fieldOne = $scope.businessDetails.post_meta_fields._ait-item_item-data;
and i want to print:
{{fieldOne}}
i know that the problem with underscore and hyphen but how can i get the meta data with them ?
this is the error in console:
ReferenceError: item_item is not defined
at itemSingleCtrl.js:13
at angular.js:16170
at m.$eval (angular.js:17444)
at m.$digest (angular.js:17257)
at m.$apply (angular.js:17552)
at l (angular.js:11697)
at K (angular.js:11903)
at XMLHttpRequest.y.onload (angular.js:11836)
Since your property contains - in it, you can't use dot notation to access its value. You have to access it like below
$scope.fieldOne = $scope.businessDetails.post_meta_fields["_ait-item_item-data"]
I want to change page URL by $windows.location.href. I'm using theses query parameters (parameter values are encoded by java.net.URLEncoder.encode(param, "UTF-8")):
number: Numeric value
src: English characters
path: e.g. https://127.0.0.1/callId=123456
desc: Non-english characters
Whole url example:
/app/index.html#/cm/calls/save?number=23390221&src=phoneNumber&path=http%3A%2F%2F127.0.0.1%2FcallId%3D123456&desc=%D9%81%D8%A7%DB%8C%D9%84+%D8%AA%D9%85%D8%A7%D8%B3+%D8%B5%D9%88%D8%AA%DB%8C
When using $windows.location.href:
$window.location.href = notification.url;
I'm getting following error (only for first time):
Uncaught Error: [$rootScope:infdig] http://errors.angularjs.org/1.4.14/$rootScope/infdig?p0=10&p1=%5B%5D
at angular.js:38
at n.$digest (angular.js:16266)
at angular.js:12606
at angular.js:5943
at p (angular.js:341)
at h (angular.js:5942)
at f (angular.js:5910)
at dispatch (jquery.js:4665)
at r.handle (jquery.js:4333)
But in theses situations i'm not getting any error:
Using only number and src parameters
Using only digit/English characters for path and desc parameters
After first time (This error only occurs if we are visiting that url for first time)
Note: I did not do anything with these parameters in client-side codes yet!
I'm writing an AWS reliant application in javascript and I'm utilizing the AWS CLI to automate the build process for my AWS resources. I'm attempting to create an API Gateway resource with CORS enabled. While calling the put-integration-response method of the api gateway CLI, when I add the --response-parameters argument, I received the following error:
>> Error parsing parameter '--response-parameters': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
>> JSON received: {method.response.header.Access-Control-Allow-Origin:'*'}
Here is the --response-parameters argument that is causing issues:
--response-parameters {"method.response.header.Access-Control-Allow-Origin":"\'*\'"}
If it helps, this argument is being fed via the grunt-exec plugin for Grunt. What exactly is causing this issue? I've tried adding more double quotes, but they don't seem to appear in 'JSON received'.
Here is another fix for this problem from here
Basically you use \ before quotes inside of JSON on Windows:
Linux/Mac:
--expression-attribute-values '{ ":u": {"S":"anotherUser"}}'
will be like this on Windows:
--expression-attribute-values '{ \":u\": {\"S\":\"anotherUser\"}}'
Hope it helps to fix your error
I had the same problem while following an AWS Lambda Functions tutorial
where I couldn't get the response-models argument to accept JSON (on Windows 10) no matter what I tried. I finally figured it out: I created a file named response-models.json with the contents on the first line of the file as {"application/json": "Empty"} and I saved it in the current directory. Then as the value of the response-models argument I used file://response-models.json
IMPORTANT: the file must be saved in a format WITHOUT the BOM so that only the ASCII characters will come out of it and no other gibberish. (I used Sublime Text which allows one to save in UTF-8 with no BOM, as well as many other formats.)
Et Voila! I got back the following response:
{
"statusCode": "200",
"responseModels": {
"application/json": "Empty"
}
}
You can encode the static value by "'"'"'*'"'"'".
Example:
aws apigateway put-integration-response --rest-api-id xxxxx --resource-id xxxxxx --http-method GET --status-code 200 --response-parameters '{"method.response.header.Access-Control-Allow-Origin": "'"'"'*'"'"'"}'
I suggest to use the JavaScript SDK to call API Gateway to manage your resources. You can find more information from the SDK documentation.
I am having a weird problem that I hope you can help me with.
I have Highcharts running on a dev website -- I use a simple form to allow the user to enter data.
On the same page, a Highchart shows once data is entered.
The data entry form has very simple jQuery-based snippets, eg. form validation, a counter for max number of characters, etc.
What happens is that when there is chart data in the database, the chart plots correctly, and the remaining JS snippets work as expected wen you try to enter new datapoints.
But if there is no data in the database (therefore no Highchart is shown), all my JS snippets stop working.
On Firebug console, I get this error when there is no data to form a chart:
jb is null
function n(m,h){kc=ya(a.title,m);tc=ya...play:""});Aa.body.appendChild(Qb)}Tc=
highcharts.js (line 47)
On Chrome, a different error shows as
Uncaught TypeError: Cannot set property 'innerHTML' of null
d.d.extend._Deferred.f.resolveWith jquery.min.js:16
d.d.extend.ready jquery.min.js:16
d.c.addEventListener.A
Again, these errors disappear as soon as I enter the first data point and a chart is formed.
Does anyone know what is happening and how I can get my JS to work when a Highchart is empty?
Any pointers are much appreciated. Thanks!
For me the problem was that I wasn't including jQuery before including HighCharts.
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Threw the errors:
Uncaught TypeError: Cannot read property 'addEvent' of undefined(anonymous function) # highcharts.js:313(anonymous function) # highcharts.js:315(anonymous function) # highcharts.js:331
Uncaught TypeError: n.getOptions is not a function(anonymous function) # highcharts-more.js:8(anonymous function) # highcharts-more.js:55
Uncaught TypeError: Cannot read property 'fireEvent' of undefined(anonymous function) # exporting.js:9(anonymous function) # exporting.js:24
But if I included jQuery first it didn't.
I had this problem. I had to surround the highChart creation code with document.ready
$(document).ready({
chart = new Highcharts.Chart({ //my cool chart
});
});
OK, this error popped up again and that's because my comment above did not really solve it.
Here's the culprit: if you have a model that generates data for charts happen to return an empty array (say it's a new user and she hasn't added any data yet to the database), this empty array is passed to the controller -- which will then pass the empty array to the view with Highcharts.
When passing an empty array to my view containing Highcharts, Highcharts would run but would not find an element to inject the chart, because I also had a condition in the view that removed #container if there was no data.
Without where to put the chart, Highcharts returns an innerHTML error, that may or may not break your remaining javascript (my case).
The solution here had nothing to do with JS, but actually with putting a condition in my controller which would be in pseudo code:
if model that generates chart data returns empty array
don't generate view containing Highcharts
else
generate view containing Highcharts
Doing this not only I prevented the error for good but also reduced the overhead of running Highcharts when no data is present.