At https://rawgit.com/UserName/master/file.json (dummy URL) I am hosting a JSON file.
The exact JSON file being hosted it this:
[
{
"name":"Europe",
"id":1
},
{
"name":"USA",
"id":2
}
]
And when I try to obtain this via AngularJS:
return{
fetchData : function(remoteDataId){
var deferred = $q.defer();
var url = 'https://cdn.rawgit.com/Username/master/' + remoteDataId;
$http.get(url, { cache:true }).then
(
function(resp){
deferred.resolve(resp.data)
},
function(err){
deferred.reject();
}
)
return deferred.promise;
}
};
I get this error : Refused to execute script from 'https://rawgit.com/UserName/master/file.json?callback=angular.callbacks._3' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
What is wrong here? According to JSLint my JSON is valid. Should I add anything to the .json file?
I changed $http.jsonp() to $http.get(). It works even though it is a cross origin request.
Related
I'm getting this error when calling $.connection.hub.stop();
Refused to execute script from ... because its MIME type ('') is not executable, and strict MIME type checking is enabled.
SignalR Client: jquery.signalR-2.2.3.min.js
SignalR Server: All Nugets are up to date
Startup.cs
app.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
var Configuration = new HubConfiguration
{
EnableJSONP = true,
EnableJavaScriptProxies = true,
EnableDetailedErrors = true
};
map.RunSignalR(Configuration);
});
Javascript
$.connection.hub.start({ jsonp: true }).done(function () { ... });
Any ideas about fix?
I have a javascript code that gets the xml list http://BUCKETNAME.s3.REGION.amazonaws.com/ of s3 bucket and uses it as a playlist:
AWS.config=
{ "accessKeyId": "ACCESS KEY",
"secretAccessKey": "SECRET KEY",
"region": "REGION" };
// Create S3 service object
s3 = new AWS.S3();
var params = {
Bucket: 'BUCKET NAME', /* required */
Delimiter: '',
EncodingType: 'url',
Marker: '',
MaxKeys: 0,
Prefix: '',
RequestPayer: 'requester'
};
s3.listObjects(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else
{
console.log('the list is approved '); // successful response
// Here is the function that convert the file list in the xml to an array
var b = document.documentElement;
b.setAttribute('data-useragent', navigator.userAgent);
b.setAttribute('data-platform', navigator.platform);
var radioName;
var radioTitle;
var tracklength= 0;
// setupPlayer function
function setupPlayer(href,name){
radioName= href;
radioTitle= name;
$.ajax({
type: "GET",
url: "http://BUCKETNAME.s3.REGION.amazonaws.com/?prefix=radio/"+radioName+"/",
dataType: "xml",
success: function(xml){
//tracklength=0;
tracks =[];
$(xml).find('Contents').each(function(){
tracklength=tracklength+1;
tracks.push({
"track": tracklength,
"file" : $(this).find('Key').text()
});
});
radio(tracks);
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
}
}
As you can see, in this code I am taking the XML file and add a radio name (which is the folder name) , after that the ajax will save all the file names in this folder to an array tracks.
This code works perfectly if there is a list grantee permission for Everyone. So there is no need for aws config here. I can run the code inside else statement in listObjects function and it will give me the same response.
What I do want is to give the grant access to this key only, to make this function not work without the access key and secret key.
So no one can access the xml list except those who have the access and secret keys.
Is that possible ?
(This is not the full code, but you got the Idea, accessing the XML file of the bucket and getting the keys an saving them to an array).
You should use s3.getObject (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getObject-property) to get your xml files instead of $.ajax call.
My chrome extension keeps throwing an error to this function
function messageReceived(message) {
// A message is an object with a data property that
// consists of key-value pairs.
// Pop up a notification to show the GCM message.
chrome.notifications.create(getNotificationId(), {
title: message.data.name,
iconUrl: 'assets/img/cat.jpg',
type: 'basic',
message: message.data.prompt,
buttons : [
{ title: "Accept" },
{ title: "Reject" }
]
}, function() {});
}
Error:
Unchecked runtime.lastError while running notifications.create: Some of the required properties are missing: type, iconUrl, title and message.
at messageReceived
However, all these are actually present. The error arrives EVERYTIME I add the following function
function notificationBtnClicked(notification, ibtn) {
console.log(notification)
console.log(ibtn)
if (ibtn==0) {
chrome.storage.local.get("name", function(name){
chrome.storage.local.get("email",function(email){
//call other users
var email = email
var name = name
$.ajax({
url: 'some api',
data:'{email:email, name:name}',
ajax:true,
success: function(result)
{
alert(result);
}
});
});
})
}else {
//snooze
}
}
But, I don't understand what's the issue. I checked the chrome.storage by downloading some chrome extension that lets you view it and its there.
Why is the error incorrect? :/
chrome.gcm.onMessage.addListener(messageReceived);
chrome.notifications.onButtonClicked.addListener(notificationBtnClicked);
Make sure that all required notification properties have their value. The 'iconUrl' you used must be a data URL, a blob URL or URL related to a resource within the extension's .crx file required for 'notification.create' method. Please be mindful of the Chrome version you are using.
Also, include a callback and check chrome.runtime.lastError
function callback() {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
} else {
// Tab exists
}
}
In Chrome Apps, I'm downloading a blob content from a server using JavaScript XHR (Angular $http GET in particular, with response type 'blob')
How should I save this to chrome application's file system?
Currently using an Angular wrapper on HTML5 filesystem API
https://github.com/maciel310/angular-filesystem
I do not want to show user a popup (hence I can't use chrome.fileSystem. chooseEntry )
The chrome.fileSystem.requestFileSystem API is only supported by Kiosk-only apps.
Hence I'm using HTML5 FileSystem API instead of chrome's.
I'm using following code to make XHR to fetch blob.
$http({
url: SERVER_URL+"/someVideo.mp4",
method: "GET",
responseType: "blob"
}).then(function(response) {
console.log(response);
fileSystem.writeBlob(response.name, response).then(function() {
console.log("file saved");
}, function(err) {
console.log(err);
});
}, function (response) {
});
This is my writeBlob method
writeBlob: function(fileName, blob, append) {
append = (typeof append == 'undefined' ? false : append);
var def = $q.defer();
fsDefer.promise.then(function(fs) {
fs.root.getFile(fileName, {create: true}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
if(append) {
fileWriter.seek(fileWriter.length);
}
var truncated = false;
fileWriter.onwriteend = function(e) {
//truncate all data after current position
if (!truncated) {
truncated = true;
this.truncate(this.position);
return;
}
safeResolve(def, "");
};
fileWriter.onerror = function(e) {
safeReject(def, {text: 'Write failed', obj: e});
};
fileWriter.write(blob);
}, function(e) {
safeReject(def, {text: "Error creating file", obj: e});
});
}, function(e) {
safeReject(def, {text: "Error getting file", obj: e});
});
}, function(err) {
def.reject(err);
});
return def.promise;
},
This shows SECURITY_ERR as It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.
What's the solution for this?
I've tried using --allow-file-access-from-files flag while launching app. It doesn't help.
Chrome Application's sandbox storage doesn't allow files to be stored in root directory (i.e. / )
Modify the code to save it in a specific sub-directory under it.
For example -
fileSystem.writeBlob("/new"+response.name, response).then(function() {
console.log("file saved");
}, function(err) {
console.log(err);
});
This would successfully save the file under /new/ directory.
To expand on this, here is a full example app on how to download a file and save the blob and display it back to the user.
https://github.com/PierBover/chrome-os-app-download-example
I have used filefield xtype to upload a file and calling a web service.
For my application, to handle success and failure block, i am using a variable 'success' such that if the value is true, it goes to success block and if the value is false, it goes to failure block.
If i set the value success=false, it comes to failure block but, when i decode the response it gives me "permission denied" error only in IE. In Chrome, we get the expected output even if it enters the failure block.
Since i am getting this error, i am handling this failure case in success block itself.
Below is the code snippet:
form.submit({
headers : {
"Accept" : "application/json; charset=utf-8"
},
url : 'calling a web service',
waitMsg : 'Loading... Please Wait...',
success : function (response, args) {
var jsonResp = Ext.decode(args.response.responseText);
if (jsonResp.exception) {
Ext.create('widget.uxNotification', {
title : 'Failed',
height : 150,
width : 350,
html : '<span style="text-align:center; display:block;color:red">' + jsonResp.R.MSG + '</span>'
}).show();
} else {
//actual code if success=true goes here
}
},
failure : function (response, args) {
var jsonResp = Ext.decode(args.response.responseText); //if i decode the response, i get permission denied
var msg = jsonResp.R.MSG || jsonResp.R.Message;
//R.MSG is undefined even if it is present in response and R.Message gives permission denied
Ext.Msg.alert(msg);
}
});
json Response for success case:
{
"success":true,
"R":{
"MSG":"Success"
}
}
json Response for failure case:
{
"success":true,
"exception":true,
"R":{
"MSG":"Failure"
}
}
I am sending another parameter 'exception' in the response to handle this. So if exception is true then it's actually a failure case.
Is it a bug in ExtJS library? Since i have seen the comments written in library file, stating that there is a problem with iframe.
Can anyone help me on how to solve this IE issue?