import data into H2 via API - html

I'm a programming beginner. . Now I'm having a problem that I struggle to solve ... I want to write a numeric data in the H2 tag that I import via API call. I have tried in various ways, making a console log the data exists but it seems that I am wrong something to richamarlo in H2. I seek help in understanding and resolving this error. Thank you
enter code here
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script>
const intervalTime = 10 * 1000;
const container = document.getElementsByClassName("u-text u-text-palette-3-base u-title u-text-3");
const endpoint = "https://*************/v0/*******/************************/collections/****************?offset=0&limit=unlikely";
function onInterval() {
fetch(endpoint, {
method: "GET",
headers: { Authorization: "Bearer **********************" }
})
.then((res) => res.json())
.then((data) => {
const title = data.records.map((a) => {
return{
close: (a.close)
};
});
const lastClose = title[title.length - 1];
console.log(lastClose);
});
}
onInterval();
window.setInterval(onInterval, intervalTime);
</script>
</head>
<body>
<h2><p class="u-text u-text-palette-3-base u-title u-text-3"></p>
</h2>
</body>
</html>

Related

IPFS in browser: testing a simple file fetch

I want to download this file and print its contents to the console using an in-browser IPFS node. The following html file should do the job:
<!doctype html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
</title>
</head>
<body>
<script type='text/javascript' src='https://unpkg.com/ipfs#0.55.1/dist/index.min.js'></script>
<script type="text/javascript">
var ifile = 'Qmc3zqKcwzbbvw3MQm3hXdg8BQoFjGdZiGdAfXAyAGGdLi';
(async () => {
const inode = await Ipfs.create({
config: {
Addresses: {
Swarm: [
// These webrtc-star servers are for testing only
'/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
]
},
Bootstrap: []
}
})
window.inode = inode; //For poking
for await (const chunk of inode.cat(ifile)) {
console.log(chunk.toString());
}
})();
</script>
Testing IPFS file fetch
</body></html>
But it doesn't print anything. What am I missing?
You don't have any bootstrap nodes, so it can't find the CID. If you add my node for example, it works fine:
<!doctype html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
</title>
</head>
<body>
<script type='text/javascript' src='https://unpkg.com/ipfs#0.55.1/dist/index.min.js'></script>
<script type="text/javascript">
var ifile = 'Qmc3zqKcwzbbvw3MQm3hXdg8BQoFjGdZiGdAfXAyAGGdLi';
(async () => {
const inode = await Ipfs.create({
config: {
Addresses: {
Swarm: [
// These webrtc-star servers are for testing only
'/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
]
},
Bootstrap: []
}
})
window.inode = inode; //For poking
await inode.swarm.connect("/dns6/ipfs.thedisco.zone/tcp/4430/wss/p2p/12D3KooWChhhfGdB9GJy1GbhghAAKCUR99oCymMEVS4eUcEy67nt");
for await (const chunk of inode.cat(ifile)) {
console.log(chunk.toString());
}
})();
</script>
Testing IPFS file fetch
</body></html>

asp.net ajax upload file always get null

I am trying to upload a file using jquery ajax, I can see the file object, its name, its size, etc.
In console by formdata.get("files"), but the context.request.files size is always zero, it seems the server does not receive the file from client, the HttpPostedFileBase request is always null.
How to fix it?
HTML:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="UploadKpData.aspx.cs" Inherits="WebApp.Admin.UploadKpData" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="./../Scripts/jquery-1.4.4.min.js"></script>
</head>
<body>
<div>
<div>
<input type="file" id="kpData"/>
<button type="submit" id="uploadKp" />
</div>
</div>
</body>
<script>
$("#uploadKp").click(function () {
var formdata = new FormData();
var files = $("#kpData").get(0).files[0];
formdata.append("files", files);
$.ajax({
url: "../../ds/UploadExcel.ashx",
type: "POST",
async: false,
contentType: false, // Not to set any content header
processData: false, // Not to process data
data: formdata,
success: function (result) {
alert(result);
},
error: function (err) {
alert(err.statusText);
}
});
})
</script>
</html>
UploadExcel.ashx:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApp.ds
{
public class UploadExcel : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
HttpFileCollection file = context.Request.Files;
HttpPostedFile file1 = file[0];
string fileName = context.Server.MapPath("~/tmp/" + "test2.xlsx");
file1.SaveAs(fileName);
context.Response.ContentType = "text/plain";
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
I have checked your code and all are working for me.
Let me share some screenshots :
Handler get file:
Project structure:
HTML page:

Why figure and oembed tags are not working?

Given the following html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
<h2>Header</h2>
<figure>
<oembed url="https://www.youtube.com/watch?v=7km4EHgkQiw&list=RDQK-Z1K67uaA&index=9"></oembed>
</figure>
</body>
</html>
Why the page is not showing the youtube video?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
<h2>Header</h2>
<figure>
<oembed url="https://www.youtube.com/watch?v=7km4EHgkQiw&list=RDQK-Z1K67uaA&index=9"></oembed>
</figure>
</body>
</html>
The body code was generated by CKEditor (I just removed the class "media" from the figure tag). You can see my original post here link
Solution tested for CKeditor 5
Save the exact view showing in CKeditor into DB use the below code
mediaEmbed: {
previewsInData:true
},
Full JS Code
var KTCkeditorDocument = function () {
// Private functions
var demo = function () {
ClassicEditor
.create( document.querySelector( '#kt-editor' ),{
mediaEmbed: {
previewsInData:true
},
}
)
.then( editor => {
// console.log( editor );
} )
.catch( error => {
// console.error( error );
Swal.fire("Info !", error, "error");
} );
}
return {
// public functions
init: function() {
demo();
}
};
}();
jQuery(document).ready(function() {
KTCkeditorDocument.init();
});
For more details you can check this link: https://ckeditor.com/docs/ckeditor5/latest/features/media-embed.html
The figure and oembed tags are not going to work to show a preview. In order to make it work I had to convert the youtube links to embeddable links and add them with an iframe.
To do so I used the solution proposed in this thread: link
function getId(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match && match[2].length == 11) {
return match[2];
} else {
return 'error';
}
}
var videoId = getId('http://www.youtube.com/watch?v=zbYf5_S7oJo');
var iframeMarkup = '<iframe width="560" height="315" src="//www.youtube.com/embed/'
+ videoId + '" frameborder="0" allowfullscreen></iframe>';

Authenticating with Facebook Graph API & Parsing JSON Reviews from a Facebook Page

I am having trouble authenticating and parsing.
get Facebook Graph api page review
I have tried to submit the app for review and request manage_page access but I get an error:
"Invalid Scopes: manage_pages. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at: developers.facebook.com/docs/facebook-login/permissions" and possibly the API is deprecated
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<title>Ilan's Test</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div id="results">
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
<script>
var myurl = "http://graph.facebook.com/v3.3/FinancialSanityNow/ratings";
var getToken = function(req, res) {
var facebookToken = req.headers['facebooktoken'];
//TODO : check the expirationdate of facebooktoken
if(facebookToken) {
var path = 'https://graph.facebook.com/v3.3/FinancialSanityNow?access_token=' + facebookToken;
request(path, function (error, response, body) {
var facebookUserData = JSON.parse(body);
if (!error && response && response.statusCode && response.statusCode == 200) {
if(facebookUserData && facebookUserData.id) {
var accessToken = jsonWebToken.sign(facebookUserData, jwtSecret, {
//Set the expiration
expiresIn: 86400
});
res.status(200).send(accessToken);
} else {
res.status(403);
res.send('Access Forbidden');
}
}
else {
console.log(facebookUserData.error);
//console.log(response);
res.status(500);
res.send('Access Forbidden');
}
});
res.status(403);
res.send('Access Forbidden');
}
};
$.ajax({
url: myurl,
headers: {
'access_token':'xxxxxaccesstokenherexxxxx',
},
method: 'GET',
dataType: 'json',
success: function(data){
$.each(data.reviews, function(i, item) {
// Store each review object in a variable
var reviewdata = item.data.reviews;
// Append our result into our page
$('#results').append('test:' + reviewdata);
});
}
});
</script>
</body>
</html>
I just want to know if this is even possible through pages/ratings api from facebook
https://developers.facebook.com/docs/graph-api/reference/page/ratings/
Most permissions need review before you can use them. Without review, they will only work for users with a role in the App, and you need to keep the App in dev mode. If you put it live, unapproved permissions will not work at all.
Also, you have to use a Page Token of the Page in question to get reviews, you get a Page token by using the /me/accounts?fields=access_token endpoint, with a User Token that includes the manage_pages permission.
More information about Tokens: https://developers.facebook.com/docs/facebook-login/access-tokens/

Unexpected token < when using reactjs app

I have been following a video tutorial which apparently using JSBin to show its code, when I tried out the code locally then it does not work for me. Could someone please help me to figure out what is the issue.
Below is the code
<!DOCTYPE html>
<html>
<head>
<title>Redux basic example</title>
<script src="https://unpkg.com/redux#latest/dist/redux.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react.min.js" type = "text/babel"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react-dom.min.js" type = "text/babel"></script>
</head>
<body>
<div id='root'>
</div>
<script>
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
}
};
const Counter = ({ value}) => (<div>{value}</div>);
const { createStore } = Redux;
var store = createStore(counter);
const render = () => {
ReactDOM.render(
<Counter value={store.getState()} onIncrement = {
() => store.dispatch({type: 'INCREMENT'})
}
onDecrement = {
() => store.dispatch({type: 'DECREMENT'})
} />,
document.getElementById('root')
);
};
store.subscribe(render);
render();
</script>
</body>
</html>
You are using JSX in your code, which needs to be transpiled into standard javascript before executing it in the browser.
const Counter = ({ value}) => (<div>{value}</div>);
Look into Babel
The browser is complaining about the JSX code. You should transpile it to regular Javascript before including it in your page. There are several ways to do: Webpack, Babel...
Have a look to create-react-app npm package to get started fast: https://github.com/facebookincubator/create-react-app