"Permission Denied" error in IE when it enters failure block, ExtJS - javascript

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?

Related

Typeerror when pulling json data from Github

I'm using d3.json to pull a json link from Enterprise GitHub (same repo/folder that the js file is in.
d3.json("https://raw.github.exampleEnterprise.com/path/to/repo/data.json?token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",function(error, flare) {
console.log(flare);
root = flare;
update(root);
});
And I'm getting the error TypeError: flare is undefined
When I pull it from a public GitHub, it all works fine
d3.json("https://raw.githubusercontent.com/path/to/repo/data.json",function(error, flare) {
console.log(flare);
root = flare;
update(root);
});
When I paste the enterprise link with token in the address bar of a browser, I can see the whole JSON file. So it's odd that it's not coming through, or why.
EDIT:
I've added an error return,
d3.json("https://raw.github.exampleEnterprise.com/path/to/repo/data.json?token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",function(error, flare) {
if(error){ console.log("There was an error", error); }
console.log(flare);
root = flare;
update(root);
});
and can see that the error I'm receiving is:
There was an error XMLHttpRequest { onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, responseURL: "", status: 0, statusText: "", responseType: "", response: "" }
EDIT 2: Looking in the Network tab, I saw a 200 response to my GET request. When checking the "Response" tab of the request I could see a red error: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data I tried using d3.text() instead of d3.json(), which still returned "undefined" (as I could see in the console). So that explains that error.
In that callback you are not checking if there is an error.
If there is an error, data will be undefined.
If you were to do something like this:
d3.json("__url__", function(error, data){
if(error){ console.log("There was an error", error); }
else{
console.log("Here is your data: ", data);
}
})
You can see if there is an error, and as long is there not one, then you can access the data object.
Hope this helps.

Chrome extension - GCM Notification throws error but information is there?

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
}
}

Catching errors in AngularJS when using $resource

Searching product is working fine when product is found, but if user search with letters, or bad criteria, nothing happens. I can see the error message in JavaScript-console and in Header there is Status Code 204, no Content. I think that Angular is just working badly, when empty object is coming back. How can I tell an user that there is no products with his/her criteria, cause I can't catch the error message at all at the moment. What is the correct and best solution to handle this? Catching errors or solving that result was empty and showing an error message in HTML-page?
Service:
return $resource(
'http://localhost:8080/RMAServer/webresources/com.rako.entity.jdeserials/:id',
{},
{
get: { method: 'GET',isArray:false, params: {id: '#serial'} },
update: { method: 'PUT', params: {id: '#serial'} }
});
Controller
//Searching product with serial number/LOTN
$scope.searchProduct = function () {
$scope.serials = lotnSvc.get({id: $scope.serial}).$promise.then(
function (data) {
var litm = data.litm;
productSvc.get({id: litm}, function (product) {
$scope.product = product;
getBrands();
},function(error){
alert('ERROR when searching product');
console.log("error---->" + error);
});
},function(error){
alert('ERROR when searching product');
console.log("error---->" + error);
});
};
Error message in javaScript console
Error: [$resource:badcfg] Error in resource configuration for action `get`. Expected response to contain an object but got an array
http://errors.angularjs.org/1.3.15/$resource/badcfg?p0=get&p1=object&p2=array
at REGEX_STRING_REGEXP
Status code in Header
Just try to send the success and the error handlers as second and third parameters to "get" function instead of using promises. There was the same problem: How to handle $resource service errors in AngularJS

Refused to execute script from '*'

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.

How to make HTTPS requests with serverside javascript using Worklight?

I'm toying around with IBM worklight, and am trying to create an adapter to feed some data in from the Google places API.
I want to call this URL :
https://maps.googleapis.com/maps/api/place/search/json?key=AIzaSyCTlPms1pvhzeoRrBao5qW-DJMI_CWcbAM&location=52.0700,1.1400&radius=10000&sensor=false&name=coffee
Executing this URL works fine in a browser, and displays some nice JSON that I'm trying to obtain via Worklight.
The Worklight adapters are created in Javascript, this is what I have so far :
function getCoffeeHouses() {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'maps/api/place/search/json',
parameters : {
'key' : 'AIzaSyCTlPms1pvhzeoRrBao5qW-DJMI_CWcbAM',
'location' : '52.0700,1.1400',
'radius' : '10000',
'sensor' : 'false',
'name' : 'coffee'
}
};
var response = WL.Server.invokeHttp(input);
// Extract latitude and longitude from the response.
var type = typeof response;
if ("object" == type) {
if (true == response["isSuccessful"]) {
// Return JSON object with lat and lng.
return response["results"];
}
else {
// Returning null. Web request was not successful.
return null;
}
}
else {
// Returning null. Response is not an object.
return null;
}
}
And this is the result that I get in the console, when I test the above:
Failed to parse JSON string
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}#media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
</style>
<a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
<p><b>404.</b> <ins>That’s an error.</ins>
<p>The requested URL <code>/maps/api/place/search/json?key=AIzaSyCTlPms1pvhzeoRrBao5qW-DJMI_CWcbAM&location=52.0700%2C1.1400&radius=10000&sensor=false&name=coffee</code> was not found on this server. <ins>That’s all we know.</ins>
Caused by: java.io.IOException: Unexpected character '<' on line 1, column 1
[2012-07-23 11:08:57] An error occurred while invoking procedure CoffeeFinder/getCoffeeHouses parameters: {
"arr": [
]
}
null
Caused by: null
I think, that this is probably caused because the adapter is requesting as HTTP, whereas it should be using HTTPS.
If I alter the request to use HTTP in a browser, it displays similar results.
Question : Can I make an HTTPS request by altering the above Javascript, or am I misunderstanding worklight adapters?
Looks like googleapis will not work if you don't specify Host header inside of your request.
After adding it everything works as it should:
This is adapters's XML section
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>https</protocol>
<domain>maps.googleapis.com</domain>
<port>443</port>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>
This is adapter's JS:
function doGet() {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'maps/api/place/search/json',
headers: {
Host: 'maps.googleapis.com'
},
parameters : {
'key' : 'AIzaSyCTlPms1pvhzeoRrBao5qW-DJMI_CWcbAM',
'location' : '52.0700,1.1400',
'radius' : '10000',
'sensor' : 'false',
'name' : 'coffee'
}
};
var response = WL.Server.invokeHttp(input);
return response;
}
in your adapter there is also an {ADAPTER NAME}.xml
In it, under connectivity under connectionPolicy, there is the protocol.
did you change it to https and deploy?

Categories

Resources