Error when getting angular-translate JSON files in angular app - json

I have an angular app with some i18n JSON files. The files work fine- the language of the site is changed perfectly depending on which one is selected. However, I get a funny console error which I can't figure out-
Uncaught SyntaxError: Unexpected token : at en.json: 2
Resource interpreted as Script but transferred with MIME type application/octet-stream
The same error appears in the console for each file.
Is there something wrong with the way my file is structured?
example of data in en.json:
{
"WELCOME" : "Welcome",
"HOME" : "Home",
"GO" : "Go",
"LOGOUT" : "Log Out"
}

There's nothing wrong with your JSON file but, according to the console log, it seems your web server does not set correct response header Content-Type which should be application/json.
So your browser tries to interpret your file as a JavaScript file and find an invalid token.
For instance with Nginx, you could use mime type configuration file provided by HTML5-Boilerplate project (https://github.com/h5bp/server-configs-nginx/blob/master/mime.types) and include it into your Nginx configuration:
include /etc/nginx/mime.types;
It contains the following directive setting application/json as content type for JSON:
types {
application/json json;
}

Related

POST in JMeter gives "Unrecognized token 'json'"

I can not figure out why I get this error:
"Failed to parse request body as JSON resource. Error was: Failed to parse JSON encoded FHIR content: Unrecognized token 'json': was expecting ('true', 'false' or 'null')\n at [Source: UNKNOWN; line: 3, column: 29]"
FHIR is the standard used. I also tested with a valid JSON that worked with Postman, so I don't think the actual JSON is the issue.
I'm not sure if I'm correct, but it seems JMeter adds 'json' from somewhere as the error states the token 'json' is unexpected. This is the Request > Request body tab in View Results Tree.
This is just a test JSON, but I got the same response with a JSON body that is working in Postman (and I formatted correctly to be sure). I have the Content-Type header specified. I simply don't understand where the token 'json' would come from as my json itself doesn't contain the token. Does anybody know if JMeter adds something to the request?
You're sending incorrect payload, it should look like:
{
"test" : "X"
}
and you are sending
{
"test" : "X"
}json
^^^^ this guy is causing the issue
JMeter doesn't add anything to request, you need to double check your configuration, i.e. JMeter jmx scripts are "normal" XML files so you can use your favorite text editor to look up this json
If you're able to send a valid request using Postman you should be able to record it using JMeter's HTTP(S) Test Script Recorder, just configure Postman to use JMeter as the proxy and run your request/collection - JMeter will capture the requests and generate relevant HTTP Request samplers which can be replayed successfully.
More information: How to Convert Your Postman API Tests to JMeter for Scaling
It happened to be that if you add a default parameter in an HTTP Request Defaults (in my case _format=json), it would add it to the body of the POST.
I fixed this by adding a BeanShell PreProcessor with the code:
if(sampler.getMethod().equalsIgnoreCase("get")){ sampler.addArgument("_format", "json"); }

Using file as payload in Advanced REST Client

I'm trying to work with the Advanced REST Client of Google.
I installed the extension, and I can work with it.
Now I wanted to use a JSON-file as input for my payload.
The JSON-file looks as follows :
{"UserName":"", "UserPassword":"","SetDebug":true}
The Content-Type is set to application/json.
But when I try to send the request I get the following error:
{
"Message": "The request entity's media type 'multipart/form-data' is not supported for this resource."
}
What am I doing wrong? Can anyone help me?
The ARC seems to override your Content-Type selection sometimes, changing it to multipart-form-data. If you select Files for the body and pick a file, it shows a message saying:
The Content-Type header will finally be changed to "multipart/form-data" during the request.
When you submit the request, it does exactly that: changes the Content-Type header. You can confirm this by looking in the Request Headers part of the output display.
I don't know if there's any way to stop it doing this :(-

knockout webmail tutorial error received

I am running through this tutorial http://learn.knockoutjs.com/#/?tutorial=webmail
I have completed it and now am trying to run on my local machine
I have taken the code from here http://learn.knockoutjs.com/WebmailExampleStandalone.html but when I put it on my local machine I get this error.
Timestamp: 7/11/2012 4:24:41 PM Error: Unable to parse bindings.
Message: ReferenceError: mails is not defined; Bindings value:
foreach: mails Source File: url/knockout/js/knockout-2.2.0.js Line: 57
The way I downloaded the JSON file was to go to learn.knockoutjs.com/knockout/mail?folder=Inbox or learn.knockoutjs.com/knockout/mail?folder=Achive depending which folder you are are on.
I just went to learn.knockoutjs.com/mail?folder=Archive and downloaded that but that saves a file called mail with no extension.
I can understand why the the other sections (except inbox doesn't work as I don't have those JSON files) but why doesn't the mail work in the first screen?
I had the same issue. The problem was that the ajax call needs to have a response header of "application/json" type in order to properly set the returned data. I'm using php so i just added header('Content-Type: application/json; charset=utf-8'); before i echoed out the json data and everything worked.

jQuery Token Input Invalid JSON primitive

I'm using this plugin:
http://loopj.com/jquery-tokeninput/
Initialized using
$("#actors").tokenInput("/Services/AutoComplete.asmx/AdminNames", {
method: "post",
theme: "facebook"
});
On typing in the input, I get this error in the NET tab of Firebug
500 Internal Server Error
Post - q=a
Response - {"Message":"Invalid JSON primitive: q.","StackTrace":" ...
JSON - "Invalid JSON primitive: q."
If I use a variable instead of Web Service, it works fine. I don't even get the debug control of the web service.
Thanks,
Dev

Html5 Mime type error in grails

I am trying to create a web application using grails 1.3.7 for iPad using a cache manifest to save the data offline. I got offline data working very fine in Chrome but in Safari, iPad and Mozilla it is giving an error saying the Application Cache manifest has an incorrect MIME type: text/plain. I have set mime type in Config.groovy as follows:
grails.mime.types = [ html: ['text/html','application/xhtml+xml'],
xml: ['text/xml', 'application/xml'],
text: 'text/plain',
js: 'text/javascript',
rss: 'application/rss+xml',
atom: 'application/atom+xml',
css: 'text/css',
csv: 'text/csv',
all: '*/*',
json: ['application/json','text/json'],
form: 'application/x-www-form-urlencoded',
multipartForm: 'multipart/form-data',
manifest: 'text/cache-manifest'
]
But still the other browsers do not accept it. I am really confused whether this is a html5 problem or grails. It works in chrome.
Hey I got the solution I found out that mime type was not set in grails....In grails to set the mime type a different way is to be follwed (But still I wonder why chrome was working without mime type)............To set the mime type in grails we have to create a web.xml and add the following code to it...
<mime-mapping>
<extension>manifest</extension>
<mime-type>text/cache-manifest</mime-type>
</mime-mapping>
But in grails web.xml is created only at the time when war is build....So to create a web.xml which can be merged with original web.xml do the following
In the command line type
grails install-templates
Now in your project folder src/templates/war is created. in the war folder create the web.xml and add the code you need... hope this will help
Rather than modify the web.xml file, you can also simply set the HTTP content type header directly from your controller action via the HTTPResponse object:
response.contentType = "text/cache-manifest"
The grails.mime.types block in Config.groovy is used during content negotiation to allow you to more easily send back different responses to a request based on the inbound Accepts header.