Taking the input field from a JSON - html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test AJAX</title>
</head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
function send()
{
var index = $('#index').val();
$(document).ready(function() {
$("#submit").click(function(event){
$.getJSON('bursa.json', function(jd) {
$('#Reserved').html('<p>' + jd.response[0].index + '</p>');
});
});
});
}
</script>
<body>
<form method="get">
Select <input type="text" id="index"><br>
<input type="button" id="submit" onclick="send()" value="Submit">
</form>
<div id="Reserved" style="border:1px solid red; height: 300px; width:400px"></div>
</body>
</html>
I'm a beginner with Jquery and I've been trying to get some data from some JSON file I created for a test. Basically what I want is to be able to allow the user to select the field he wants from the json document. My json file looks like this
"response": [
{
"c": "205.84",
"h": "206.70",
"l": "204.27",
"ch": "-1.57",
"cp": "-0.76%",
"t": "1611349199",
"s": "BA",
"cty": "united-states",
"ccy": "USD",
"exch": "NYSE",
"id": "1",
"tm": "2021-01-22 20:59:59"
},
If I try to print jd.response[0].cty for example it correctly shows "united-states", but what I want as I said is to allow the user to select his own field.. With what I've done so far it only shows "undefined". Thanks in advance for the help.

Instead of using .index, use [index]:
$('#Reserved').html('<p>' + jd.response[0][index] + '</p>');
Also called bracket notation

Related

I would like to modify the output of Webgl Platform Building with Unity3D

Building with WebGL creates one HTML file and one Build folder.
Remove the Build/Aa.json file from here orIt should be modified to js.
Now I'm trying to put json's content in HTML but it doesn't work.
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity WebGL Player | TyphoonFloodRiskAssessment</title>
<script src="Build/UnityLoader.js"></script>
<script>
var json = {
"companyName": "aaaaa",
"productName": "aa",
"dataUrl": "aa_Build.data.unityweb",
"wasmCodeUrl": "aa_Build.wasm.code.unityweb",
"wasmFrameworkUrl": "aa_Build.wasm.framework.unityweb",
"TOTAL_MEMORY": 268435456,
"graphicsAPI": ["WebGL 2.0", "WebGL 1.0"],
"webglContextAttributes": {"preserveDrawingBuffer": false},
"splashScreenStyle": "Dark",
"backgroundColor": "#231F20"
};
var data = JSON.parse(json);
var gameInstance = UnityLoader.instantiate("gameContainer",
data
);
</script>
</head>
<body>
<div id="gameContainer" style="width: 1012px; height: 650px; margin: auto"></div>
</body>
</html>
The content of "var = json" is the content of aa.json.
How can you solve it?

How to use JSON correctly in an HTML email

I have an HTML-Email, that looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
</head>
<body>
<p>Do not change next section</p>
<pre>
{
"from": "..",
"to": "..",
"statistic": {..},
"creationDate": ".."
}
</pre>
</body>
</html>
Sending this Email content with Outlook-Exchange it encodes the JSON inside the HTML to:
{
"from": "...",
..
}
Sending it with Mailcatcher it works ("from": "2019-08-01",..).
I use javamail for sending and receiving emails.

Display data from Json in Angularjs

First of all, I have to say that is my first time posting on StackOverflow.. So if I post on the wrong area, sorry.
I'm beginning with angularjs, and I'm struggling into two points. 1st I've to create a connection with my mysql, witch i wasn't able until now.. 2nd I've to display the content into the HTML page.
I'm using the following code, witch includes the app.js, page.html and data.json (I'll change that later to php if I'm allowed to.)
The app.js seems to work fine, but the view (page.html) isn't display any data..
App.js
app.controller('PatientListCtrl', ['$scope', '$http', function ($scope, $http) {
$http.get('patients.json').success(function (data) {
$scope.patients = data;
});
$scope.orderProp = 'id';
}]);
patients.json
[
{
"id": 0,
"first_name": "John",
"last_name": "Abruzzi"
},
{
"id": 1,
"first_name": "Peter",
"last_name": "Burk"
}
]
Page.html
<!DOCTYPE html>
<html class="no-js" ng-app="app">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
</head>
<body>
<div data-ng-repeat="patient in patients">
{{patient.id}}{{patient.last_name}}{{patient.first_name}}{{patient.SSN}}{{patient.DOB}}
<div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.min.js"></script>
<script src="app.js"></script>
</body>
</html>
Thanks for your attention.
You have not define the controller in the view
<div ng-controller="PatientListCtrl" data-ng-repeat="patient in patients">
<li> {{patient.id}} </li>
<div>
Here is the working Fiddle

Amcharts time series data not displaying

I'm trying to pull some time and temperature data into Amcharts. The data is regularly collected temperature data (every 10 minutes). The data displays but appears to be stacked on top of each other. See example image:
Example
The data format (from a php script) is:
[{"timestamp":"2015-10-26 04:44:33","temp":24.9,"ID":"AA"},{"timestamp":"2015-10-26 04:54:31","temp":25.1,"ID":"AA"},{"timestamp":"2015-10-26 05:04:30","temp":25.2,"ID":"AA"}.....
The script code I am using is:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Indoor temperature</title>
<script src="amcharts/amcharts.js" type="text/javascript"></script>
<script src="amcharts/serial.js" type="text/javascript"></script>
<script src="amcharts/amstock.js" type="text/javascript"></script>
<script src="http://www.amcharts.com/lib/3/plugins/dataloader/dataloader.min.js">
</script>
<link rel="stylesheet" href="amcharts/style.css" type="text/css">
<script>
var chart = AmCharts.makeChart( "chartdiv", {
"type": "serial",
"dataLoader": {
"url": "/sensor-data.php?action=csv_data&id='AB'&period=24"
},
"pathToImages": "http://www.amcharts.com/lib/images/",
"categoryField": "timestamp",
"dataDateFormat": "YYYY-MM-DD HH:MM:SS",
"startDuration": 1,
"categoryAxis": {
"parseDates": true,
"autoGridCount": true,
"minPeriod" : "ss"
},
"graphs": [ {
"valueField": "temp",
"bullet": "round",
"bulletBorderColor": "#FFFFFF",
"bulletBorderThickness": 2,
"lineThickness ": 2,
"lineAlpha": 0.5
} ]
} );
</script>
</head>
<body>
<div id="chartdiv" style="width:100%; height:400px;"></div>
</body>
</html>
Can anybody point out what I am doing wrong to prevent the data from being displayed correctly?
So it turns out I had the dates not coming out of the PHP script as a date format AND I had the date being formatted wrong from a python script to the php to the javascript.
Thanks for looking at this.

chrome.history.deleteUrl not working

I just tried chrome.history.deleteURL in an HTML page and it's not working. Can anyone say where I am going wrong?
Urls.html:
<!DOCTYPE HTML>
<html>
<head>
<title>Your History</title>
<style>
body {min-width: 300px;}
</style>
<script type="text/Javascript">
function deleteURL(form){
var urlName = form.url.value;
chrome.history.deleteUrl(urlName);
}
</script>
</head>
<body>
<form onSubmit="deleteURL(this);">
Enter url here : <input type="text" name="url" />
<input type="submit" value="submit" />
</form>
</body>
</html>
manifest.json:
{
"name": "Browser History",
"version": "1.0",
"description": "Shows up the history",
"permissions": [
"history",
"tabs"
],
"browser_action": {
"default_popup": "Urls.html",
"default_icon": "history.jpg"
}
}
After executing the program I can still see the URL which I wanted to delete.
Although I have never used the chrome.history.* API before your code looks like it should work.
Have you remembered to add the required permission to your manifest?
Edit:
Doh! I just realised that your API call is invalid. Try using this updated version of the deleteUrl function;
function deleteURL(form){
chrome.history.deleteUrl({
url: form.url.value
});
}
Notice that I've wrapped the argument in an object with a url property as per the API. Don't know why I didn't see that earlier.