EmailJS message can't be sent [closed] - javascript

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 23 hours ago.
Improve this question
I'm new to EmailJS and trying to use it on my portfolio in the contact form. I tried different solutions and still showing the same error, I think I'm stuck now
I created the account, activated it, activated MFA as well, and tried multiple codes from the doc of EmailJS and from tutorials and still showing me the same error on the console. I even changed the service_id, template_id, and public key.
The error: Uncaught The public key is required. Visit https://dashboard.emailjs.com/admin/account
code on HTML:
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/#emailjs/browser#3/dist/email.min.js">
</script>
<script type="text/javascript">
(function(){
emailjs.init("My-Public-Key");
});
</script>
code on JS:
function SendMail(){ event.preventDefault();
var params ={
from_name : document.getElementById("fullname").value,
email_id : document.getElementById("email-id").value,
message : document.getElementById("message").value
}
const serviceID = "service_uzy3k87";
const templateID = "template_btcihm8";
emailjs.send(serviceID, templateID, params)
.then(res=>{
document.getElementById("fullname").value = "";
document.getElementById("email-id").value = "";
document.getElementById("message").value = "";
console.log(res);
alert("Your message sent successfully!!")
})
.catch(err=>console.log(err));
}

Related

If else displaying wrong answer when using fetch [closed]

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 1 year ago.
Improve this question
So what I'm trying to do is create an if/else statement, where if your IP is from Japan the console log will show "You are in Japan", and if your IP is from any other country the console log will show "I guess you are in the USA". The only problem is, it doesn't work. Even when I use VPN to pretend I am from Japan, the console log still displays "I guess you are in the USA".
This is the code I currently have:
async function country() {
let response = await fetch("https://ipinfo.io/json?token=8a21f471f4e583")
let CountryResponse = await response.json()
console.log(CountryResponse)
if (CountryResponse == "JP") {
console.log('You are in Japan');
} else {
console.log('I guess you are in the USA');
}
}
country()
So basically I would just like for the console log to show "You are in Japan" if the IP is from Japan, anything else the console log can show "I guess you are in the USA".
if (CountryResponse.country === "JP") {
console.log('You are in Japan');
} else {
console.log('I guess you are in the USA');
}
The api you are calling does not return only the county code but a object witch contains this information

Javascript Discord Bot 'SyntaxError: missing ) after argument list' [closed]

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
I've been trying to create a discord bot that filters certain words and then sends a message afterwards. Here is my current code:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
//runs the message looker thingy
client.on('message', async message function {
//1 blacklisted words
let blacklisted = ['communism', 'fascism', 'socialism', 'conservatism', 'racism', 'sexism', 'nazism', 'marxism'] //words put , after the word
//2 looking for words
let foundInText = false;
for (var i in blacklisted) { // loops through the blacklisted list
if (message.content.toLowerCase().includes(blacklisted[i].toLowerCase())) foundInText = true;
}
// checks casesensitive words
//3 deletes and send message
if (foundInText) {
message.delete();
client.message.send('ISM SPOTTED. OFFICIAL ISM REPORT HAS BEEN FILED AND WILL BE OVERLOOKED BY THE HIGH ISM COUNCIL. ANYTHING YOU SAY CAN AND WILL BE USED AGAINST YOU IN A COURT OF LAW. YOUR FATE SHALL BE DETERMINED.');
}
});
However I keep experiencing an error saying:
client.on('message', async message function {
^^^^^
SyntaxError: missing ) after argument list
I have placed an end bracket everywhere in the line of code and it still doesn't work. Can someone please explain the error and tell me what to do to fix it?
A function definition needs to have parentheses for its arguments, even if there are none.
function(){}

Getting random images from unsplash api? [closed]

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 3 years ago.
Improve this question
I'm new to working with API's and coding in general (started 2018) and I'm currently working with the Unsplash API. The problem is when I search for a term like "mountains", the API returns random images that have nothing to do with my search term. For example when I search "mountains" I'm getting pictures of motorbikes?! Help please! :D
Here's the HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>API-Project</title>
</head>
<body>
<input type="text" id="search" />
<button id="searchButton">Search!</button>
<p id="result"></p>
<script src="/app.js"></script>
</body>
</html>
And the js:
document.getElementById("searchButton").addEventListener("click", function() {
let accessKey = "my_access_key";
let searchTerm = document.getElementById("search").innerHTML;
//let nextPage = 1;
let url =
"https://api.unsplash.com/photos/?client_id=" +
accessKey +
"&query=" +
searchTerm +
"&page=" +
nextPage +
"&per_page=20";
// Request
fetch(url)
.then(function(data) {
return data.json();
})
.then(function(data) {
console.log(data);
document.getElementById("result").innerHTML = JSON.stringify(data);
});
});
Just like #Turnip said, if the element with id: 'search' is a form input element like;
<input type='text'/>
<textarea></textarea>
you should replace your line 3 this instead:
let searchTerm = document.getElementById("search").value;
just checked the API you using, seems the way you calling it is different from the way it's documented:
https://api.unsplash.com/search/photos?client_id=YOUR_ACCESS_KEY?page=1&query=mountains

Use xhr code error on switch/case (javascript) [closed]

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'm trying to display some modal depending on the xhr error code, but I don't know why my switch is failing:
error: function (xhr) {
var codigo_error = parseInt(xhr.status);
console.log("codigo_error: " + codigo_error);//this shows 404
switch (codigo_error){
case 404: body = "Error 404";
default: body = "Other";
}
modal(body);
}
I always get the default case but in console.log I can see the 404. i tried with case '404' but there's no difference.
And if I put if(codigo_error == 404) alert(codigo_error); I can see the alert with 404
I always use a break in my switch cases.
switch(codigo_error){
case 404:
body = "Error 404";
break;
default:
body = "Other";
break;
}
modal(body);
Try that and see if it works.

Async call not working in vanilla javascript [closed]

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
The following code is my frontend code for a http long poll. In this I am expecting the code setTimeout(getChat, 0) to call the method asynchronously. But when the getChat method's XHR is pending all following XHRs of different methods are also getting into pending state.
discussTask = function(taskId) {
taskIdChat = taskId
getChat() // initial call
}
var getChat = function() {
taskId = taskIdChat
payLoad = {
'task_id': taskIdChat,
'recent_message_id': recentMessageId
}
var xmlhttp = XHR('/chat/sync', 'POST', payLoad)
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState === 4) {
buildChat(JSON.parse(xmlhttp.responseText))
setTimeout(getChat, 0) // Async recursive call
}
}
}
var XHR = function(action, method, payLoad) {
var xmlhttp = new XMLHttpRequest()
xmlhttp.open(method, action, true)
xmlhttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
xmlhttp.send(JSON.stringify(payLoad))
return xmlhttp
}
Found the issue. The Problem was not client side. I am using flask framework which by default will run in single threaded mode. So it was not serving the async requests from client side.

Categories

Resources