I'm new to JavaScript and Ionic Framework and I have following problem.
I'm trying to access data from an external HTML file using getElementsByTagName(), because I want to get some text from the HTML file and show it in the App's list-view but it's not working.
I'm using following code in my controllers.js file:
//General
.controller('generalCtrl', function($scope) {
//Create Arrays
$scope.items = {};
$scope.item_names = {};
$scope.siteDiv = $('<div>');
$scope.siteDiv.load('website.php #somediv', function(){
$scope.item_names = $(this).document.getElementsByTagName("a");
//create list view
for(i=0; i<$scope.item_names.length; i++) {
$scope.items[i] = { title: $scope.item_names[i], id: i };
}
});
})
It seems like the array $scope.items is empty because everything worked when I defined it manually. But I'm not sure how to fix this problem.
I hope someone can help me with that problem. Thanks for your attention.
Edit 1:
I've added a try-catch function which returned following error: 'ReferenceError: Can't find variable:$'. Also it says that the %scope.item_names variable is undefined, so it seems to be unable to load the site. I would be grateful for any help. Thanks.
Related
Hi I have developed scanner application using XAML WPF bt refering below link. http://www.c-sharpcorner.com/blogs/create-wpf-browser-application-to-scan-a-document-from-scanneradf-and-flatbed-using-wia After scanning and saving file in specified location I am returning back filename to javascript functionas below.
var uploadData = [];
var ContentData = #Html.Raw(Json.Encode((Objcontent)));
window.ResponseAlert = function (responseData)
I am getting below error.
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
Please find the below error screen shot.
I am not able to find the what is the cause for error but i am getting error in the below line.
var hostScript = BrowserInteropHelper.HostScript;
hostScript.document.ResponseData(filename);
May i get some help here to find what is giving me error? Any help would be greatly appreciated. Thank you.
I am running some tests against a page using Nightwatch.js. I need to get the text content of an Ace Editor that's on the page, so that I can compare it against some JSON.
Is this possible?
Thanks in advance!
Instead, I hooked into the page's angular controller and grabbed the data I needed from there:
'is the Splash-Live schema set up correctly?': function (client) {
var pageSplashLive = client.page.pageSplashLive();
var code;
login(client);
pageSplashLive.navigate()
.waitForElementVisible('#jsonButton', 15000)
.click('#jsonButton')
.waitForElementVisible('.ace_content', 10000)
.api.execute("return angular.element($('.data-editor-form')).scope()['ctrl']['selectedData']['schema']['properties'];", [], function(response) {
code = JSON.stringify(response.value);
console.log(code);
client.assert.equal(code,
'json_goes_here');
});
},
I am programming a web application in C# MVC which dynamically loads information from a server in order to improve the speed.
Currently I have some errors and I am unable to diagnose why these are causing issues so I'll try my best to explain what's happening:
This div is created many times and grabs the ID for each project.
<div>
Open:
#{string JiraKey = item.JiraProjectKey;}
<span id="JiraOpen" onload="GetOpenJira"></span>
</div>
Then in the span, the script GetOpenJira is initiated:
<script id="GetOpenJira">
var url = "/HicVault/Projects/GetNumJiraOpenByKey";
var key = $('#JiraKey').val();
$.get(url, { input: key }, function (data) { $("#JiraOpen").html(data) });
</script>
This script SHOULD asynconously ask the controller to complete the function GetNumJiraOpenByKey with the JiraKey being used as a parameter. The function in the controller is:
[HttpGet]
public ActionResult GetNumJiraOpenByKey(string JiraProjectKey)
{
var sJql = "project = \"" + JiraProjectKey + "\" and status = \"Open\"";
var resultFieldNames = new List<string> { "resolution" };
Issues issues = new JiraClient(new JiraAccount()).GetIssuesByJql(sJql, 0, 1000, resultFieldNames);
return PartialView(issues.total);
}
Essentially this function returns an int once it has counted all of the issues for that particular project. I would like this to be done with AJAX using jQuery to load these values after the page has been loaded to vastly increase speed. (Currently without AJAX, pages take >30 sec to load).
Thanks if anyone can help.
EDIT: I suppose I should ask a question, currently with this code the page loads and after around 5 seconds, a server 500 error appears in the console stating there is an Internal Server Error. I know this is a general error, going in deeper points to the line:
"$.get(url, { input: key }, function (data) { $("#JiraOpen").html(data) ".
I am guessing either the logic of my work isn't possible in Razor MVC + JS, or I am getting the fundamentals of jQuery ajax get wrong?
rewrite your script as following...
<script id="GetOpenJira">
var url = "/HicVault/Projects/GetNumJiraOpenByKey";
var key = $('#JiraKey').val();
$.get(url, { JiraProjectKey: key }, function (data) { $("#JiraOpen").html(data) });
</script>
im new to angular so im trying something new to get used to it.
I use socket.io to get a list of images [car1...car5] and i want to dynamically inject them to the view.
in my html i have a that looks like this:
<div id="section" ng-bind-html="HTML">
</div>
and in my core.js angular script i have:
var app = angular.module('test', []);
app.factory('socket', function () {
var socket = io.connect('http://localhost:8080');
return socket;
});
app.controller('TodoCtrl', function($scope, socket)
{
socket.emit('images', {}); //send for a list of images
socket.on('returnImages', function(data)
{
for(var i =1;i<=data.list.length;i++)
{
$scope.HTML = '<img style="left:'+(i*50)+'px;" src="/images/'+data.list[i]+'"/>';
}
$scope.$digest();
});
});
but this throws an error:
Error: [$sce:unsafe] http://errors.angularjs.org/1.2.16/$sce/unsafe etc
im following the docs so im not sure whats wrong and i tried including the angular-sanitize but I cant find the cdn link i keep getting a 404
You have to make html trusted
First inject $sce service in your controller
Like this
app.controller('TodoCtrl', function($scope, socket,$sce)
{
}
Then make your html trusted
$scope.HTML = $sce.trustAsHtml('<img style="left:'+(i*50)+'px;" src="/images/'+data.list[i]+'"/>');
You need to add the request domain to white list
check this: unsafe link in angular
I'm trying to load a variable from a file using javascript. I've found some examples but I can't seem to make it work and could really use some help on getting my syntax right.
Basically, I want to load a random ad image on a page, but I would like the list of ads to be pulled from a file. Currently I'm loading the images using the following script which I found on the internet:
<script type="text/javascript">
var picPaths = [
'/images/ad-1.jpg',
'/images/ad-2.jpg',
'/images/ad-3.jpg',
'/images/ad-4.jpg'
]
var oPics = [];
for(i=0; i < picPaths.length; i++){
oPics[i] = new Image();
oPics[i].src = picPaths[i];
}
curPic = Math.floor(Math.random()*oPics.length);
window.onload=function(){
document.getElementById('imgRotator').src = oPics[curPic].src;
}
</script>
I have been trying to get the picPath variable value to load from a file (instead of stating it in the code). I found some code here on stackoverflow and tried adjusted it to the following:
var picPaths = new XMLHttpRequest();
picPaths.open('GET', '/images/liveimages.inc');
picPaths.send();
I also created the file /images/liveimages.inc which containts the following:
'/images/ad-1.jpg',
'/images/ad-2.jpg',
'/images/ad-3.jpg',
'/images/ad-4.jpg'
But, alas, it’s not working and I’m not programmer enough to fix it. :-( I'm thinking my syntax is off but my code could be off too since I am not a JavaScript guy.
Any help would be appreciated and thanks for taking the time to read (and respond) to my question! :-D
If you store the data file as JSON you can use AJAX/XMLHTTPRequest to fetch it, and JSON.parse (available in all modern browsers) to read it.
An easier way perhaps is just to have a script that contains just the data, like:
var picPaths = [
'/images/ad-1.jpg',
'/images/ad-2.jpg',
'/images/ad-3.jpg',
'/images/ad-4.jpg'
];
And then include your scripts in the correct order:
<script type="text/javascript" src="picpaths.js"></script>
<script type="text/javascript" src="ad_script.js"></script>
ad_script.js will be able to access picPaths.
You could have some server-side script generate picpaths.js for you, for instance by looking at the contents of a folder or a database and pulling the ad info from that.