I have a list of key value pair of urls and I am accessing them in function named accessUrl
. The urls which we hit are external urls and not maintained by us, i.e. I can't change the server code which sends us the response back from those urls
http.get()
on success gives me status and response.
var accessUrl = function(){
$.each(url, function(key, value)
{
$http.get(value).success(function(response,status){
$scope.status=status;
if($scope.status == "200"){
versionMap[key]=response.version;
setColor[key]='color-green';
//console.log("map "+versionMap[key]);
}
})//end of success
.error(function(err){
versionMap[key]="Down";
setColor[key]='color-red';
})//end of error
})//end of each loop
}//end of accessUrl
I am trying to make a cross origin request. At present I have CORS extension added to Chrome.
My app.js:
var express = require("express");
var app = express();
var path = require("path");
app.use("/", express.static(__dirname));
app.get('/',function(req,res){
res.sendFile(path.join(__dirname+'/index.htm'));
//__dirname : It will resolve to your project folder.
});
app.set('port', process.env.PORT);
console.log(port);
I do not want to use the CORS extension anymore. Without the extension I encountered the following error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://myurl.com (Reason: CORS header 'Access-Control-Allow-Origin' missing).
Is there a way by which we can write code in Angular to make CORS requests or any other method?
I have gone through the answers suggested at:
Yet, I couldn’t figure out what's needed.