Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
I was trying to create a website where I could put in some data, and it would send GitHub API a POST request to create a file with the specified data. I am using GitHub Pages to host.
I created a test script that should create a file once the page loads, and it worked originally, but as I came back to test it again 2 hours later, it didn't create a file. What am I doing wrong? Note: I'm using personal tokens for this, is that an issue?
Here's my code:
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Dev portal</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
Hello world
<script type="module" src="script.js"></script>
</body>
</html>
script.js:
import { Octokit } from "https://cdn.skypack.dev/#octokit/rest";
const octokit = new Octokit({
auth: 'iputmytokenhere'
})
await octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
owner: 'Skoolgq',
repo: 'skoolgq.github.io',
path: 'test2.txt',
message: 'Test commits for JSON API',
committer: {
name: 'Skool Developers',
email: 'help#skool.gq'
},
content: 'bXkgbmV3IGZpbGUgY29udGVudHM='
})
Turns out I was using an existing filename. Silly me!
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
What is the most beginner way to put some little changes into an HTML page?
For example, we need to choose between "./textC.js" and "./imgC.js" files, both having function countCows() {} of different algorithms.
I've spent lots of time browsing through "changing script src dynamically" articles, but location.reload() reloads the whole page (or a <div>, I haven't found the pattern yet), some things don't work at all, some answers use complicated high software technologies I have never seen before.
This be the template html page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Template page</title>
<link id="sizescheme" rel="stylesheet" type="text/css" href="./texty.css" media="screen"/>
</head>
<body class="custombackground">
<div id="commonblock">
<button id="coucow" onclick="countCows()">Count the cows</button>
<div id="countResult"></div>
</div>
<div id="textOnly">
Something that has nothing to do with images
</div>
<script id="counter" src="./textC.js"></script>
</body>
</html>
The caller HTML page has something like this:
<div id="initial-things" >
<button id="txb" onclick="setType("t")"> Text </button><br />
<button id="imb" onclick="setType("i")"> Image </button>
</div>
And could have done this if it were the same page as the template (but scripts do not load dynamically, see the first paragraph):
<script>
function setType(param) {
if (param == "i") {
document.getElementById("sizescheme").href = "./imgy.css";
document.getElementById("counter").href = "./imgC.js";
document.getElementById("textOnly").style.visibility = "collapse";
}
if (param == "t") {
document.getElementById("sizescheme").href = "./texty.css";
document.getElementById("counter").href = "./textC.js";
}
}
</script>
So, how does one create a page from a template?
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
My HTML document is refreshed when I submit the form. Is there any way to prevent this ??
how to send data using Ajax without refreshing the page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="#">
<input type="text" name="" id="">
<button type="submit">asdf</button>
</form>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script>
$("button").submit(function (e) {
e.preventDefault();
var dataString = $("input").val();
$.ajax({
type: 'post',
url: 'data.php',
data: { album: dataString},
success: function(response) {
alert(response);
}
});
});
</script>
</body>
</html>
You are attaching the event to the wrong HTML element. Forms have onsubmit events, buttons do not.
Replace your
$("button").submit(function (e) {
by (assuminng you add an ID of form to your form):
$("#form").submit(function (e) {
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I declare a global variable in JavaScript in header.php file but it is not accessible in footer.php file
Code:
header.php
<?php define('BASE_URL','https://example.com'); ?>
<!DOCTYPE html>
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascipt">
var baseUrl = { url:"<?php echo BASE_URL; ?>" };
</script>
<meta charset="utf-8"/>
</head>
<body>
index.php
<?php
require_once("templates/header.php");
require_once("templates/footer.php");
footer.php
<script type="text/javascript">
alert(baseUrl.url);
</script>
</body>
</html>
At here I try to access baseUrl variable in footer.php file but I get this error
Uncaught ReferenceError: baseUrl is not defined
Looking for help!
You misspelled type="text/javascript". Fix that and it should work.
You have a typo, you wrote javascipt instead of javascript in the type="..." attribute.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a html page with a button whos onclick calls a javascript function...but I have been getting a function not defined error for two days! Can someone help?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/jquery.mobile-1.2.1.css" />
<link rel="stylesheet" href="css/jqm-docs.css"/>
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jqm-docs.js"></script>
<script src="js/jquery.mobile-1.2.1.js"></script>
<script>
function doSomething(){
alert('this is a test');
}
</script>
</head>
<body>
<div data-role="dialog">
<div data-role="content" id = "test" data-theme="c">
$confirm
Cancel
</div>
</div>
</body>
</html>
This might be handy:
http://jquerymobile.com/demos/1.2.0/docs/pages/page-scripting.html
You need to stick your scripts within the page element:
<div data-role="page">
<script>
function doSomething(){
alert('this is a test');
}
</script>
<!-- the rest of your stuff -->
</div>
In fact i have passed personally with this error even with valide HTML all what you need to do is move all of your functions to the head element.
Here is a fiddle:
http://jsfiddle.net/WekEA/1/
To demonstate what i have said in the framework & change the NoWrapToHead to onload
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am very new to JavaScript and to AJAX. A friend has started helping me with a form that will post a status update to App.net, but I can't get it to work. I'm sure there are many errors in the code, but thanks in advance for any help.
<html>
<head>
<title>Post to App.net</title>
<link rel="stylesheet" type="text/css" href="style_post.css">
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script>
function post()
</script>
<script type="text/javascript" language="javascript" src="count.js"></script>
<form id="post" method="post">
<textarea name="fixlength" value="What's on your mind?" id="posttext" maxlength="256" lengthcut="true"></textarea><br>
<input type="submit" value="Post" id="submit">
</form>
<label id="limitlbl_0" ><script> parseCharCounts(); </script></label>
<script type="text/javascript">
var frm = $('#post');
var token = window.location.href.substring(45,143),
var text = $('input[type="text"]').val()
frm.submit(function () {
$.ajax({
type: 'POST',
url: 'https://alpha-api.app.net/stream/0/posts',
data: {
text: 'test'
token: + token +'
},
success:
});
return false;
});
</script>
</body>
</html>
If you are making a larger app then you will definitely need to get the ajax calls working (you can make cross-domain posts as well as gets using CORS). However, for this particular situation, there is a simpler solution:
http://developers.app.net/docs/other/web-intents/
Using web intents you can use an iframe or redirect a user to a post form very easily. Just use the right URL and you are done. No JS required at all.
Here is the example above:
https://alpha.app.net/intent/post/?text=%40adn%20When%20is%20the%20next%20meetup%3F