Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 months ago.
Improve this question
when i call Javascript function first time it work properly but second time it get error like
Uncaught TypeError: profile is not a function at HTMLImageElement.onclick
why it happening?
try to write function in head section of html as well as js file but didn't working!
function profile_detail(){
xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost/CI-social-media/index.php/profile_detail", false);
xhr.onload = () => {
if (xhr.status == 200) {
if (xhr.response) {
profile = JSON.parse(xhr.responseText);
// console.log(xhr.response);
console.log(xhr.response);
console.log(profile);
// document.getElementById("profile_photo").innerHTML =xhr.response;
document.getElementById("profile_photo").src = profile[0]["profile"];
document.getElementById("profile_name").innerHTML = profile[0]["display_name"];
document.getElementById("username").innerHTML = "#"+ profile[0]["user_name"];
}
else {
alert("something want wrong try agin later")
}
}
else {
alert("Something Want Wrong Try agin");
}
}
xhr.send();
}
function profile(){
document.getElementById("request").style.display="none";
document.getElementById("friend_list").style.display="none";
document.getElementById("msg_section").style.display="none";
document.getElementById("friend_search").style.display="none";
document.getElementById("home_mains").style.display="none";
document.getElementById("search_friend_main").style.display="none";
document.getElementById("search1").style.display="none";
document.getElementById("rrprofile-card").style.display="flex";
profile_detail();
}
There are many reasons for the that
1. In first time call the function it's remove the itself ( function )
For example you use innerHtml = "" in head section
sometimes happening
.
2. You use a same name for variable and function
Mostly having this error
Related
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 12 months ago.
Improve this question
In my else block, the second line does not appear to be running. It runs setHelperText but seems to ignore setAlertValue.
const [alertValue, setAlertValue] = useState("error");
const [errValue, setErrorValue] = useState("Error State");
const [helperText, setHelperText] = useState('Input "success" to remove error');
const handleChange = (e) => {
setErrorValue(e.target.value);
if (e.target.value === "success") {
setAlertValue(null);
setHelperText("Update input to re-enable error");
} else
setHelperText('Input "success" to remove error');
setAlertValue("error"); // this line does not run
};
<TextField
label="Error State"
message="this is an ERROR message"
alert={alertValue}
value={errValue}
onChange={handleChange}
helperText={helperText}
/>
Curly braces are missing in your code. It should be like this:
if (e.target.value === "success") {
setAlertValue(null);
setHelperText("Update input to re-enable error");
} else {
setHelperText('Input "success" to remove error');
setAlertValue("error");
};
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
It gives the Illegal return statement Error in my console, pertaining this part of the code ""return message.reply("Missing Permissions!").then(m => m.delete(5000));""
if(cmd === `${prefix}clear`){
if (message.deletable) {
message.delete();
}
if (!message.member.hasPermission("MANAGE_MESSAGES")) {
return message.reply("Missing Permissions!").then(m => m.delete(5000));
}
if (isNaN(args[0]) || parseInt(args[0]) <= 0) {
return message.reply("This is not a number").then(m => m.delete(5000));
}
let deleteAmount;
if (parseInt(args[0]) > 100) {
deleteAmount = 100;
} else {
deleteAmount = parseInt(args[0]);
}
message.channel.bulkDelete(deleteAmount, true)
.catch(err => message.reply(`Something went wrong... ${err}`));
If this code is not inside of a function, than you can't use return, as there is nothing to return it from: return can only be used inside of a function.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
So basically, I can't display the collection on my html. I get a null value error for gamesList. But when I log it to the console, I can see the contents just fine, no problems there.
// get data
db.collection('games').get().then(snapshot => {
setupGames(snapshot.docs);
});
// DOM elements
const gamesList = document.querySelector('.games');
// setup games
const setupGames = (data) => {
let html = '';
data.forEach(doc => {
const game = doc.data();
const li = `
<li>
<div class="collapsible-header grey lighten-4">${game.title}</div>
<div class="collapsible-body white">${game.content}</div>
`;
html += li
});
gamesList.innerHTML = html;
}
So here something goes wrong and for the life of me I can't figure it out.
but when I use this the data does display correctly in the console, title and content:
// setup guides
const setupGames = (data) => {
let html = '';
data.forEach(doc => {
const game = doc.data();
console.log(game);
});
}
I think, when you use get() function on a collection, it already returns you the document list, so you don't need to call snapshot.docs
There's an example here:
https://firebase.google.com/docs/firestore/query-data/get-data#get_all_documents_in_a_collection
If you want to use real time data with snapshots, try it this way:
db.collection('games').onSnapshot(snapshot => {
setupGames(snapshot.docs);
});
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
In the code below, I've defined a function called checkPassword(), which takes in a single argument, passwordCorrect, which will be either true or false.
I've also defined two variables, accessGranted and message, which currently have no values (they're undefined) and will be overwritten and defined by your if statement if you've written it correctly.
I need to write an if statement inside the function that updates the two variables, accessGranted (a boolean), and message (a string), to meet the requirements below
Requirements:
1) If passwordCorrect is true, accessGranted should have a value of true and message should have a value of 'Welcome to the admin panel!'
2) In any other case, accessGranted should have a value of false and message should have a value of 'Wrong password.'
var accessGranted;
var message;
function checkPassword(passwordCorrect) {
if passwordCorrect == true {
accessGranted = true;
message = "Welcome to the admin panel!";
}
else {
accessGranted = false;
message = "Wrong password."
}
}
console.log('Access Granted:', accessGranted);
console.log('Message:', message);
You need to call the function and fix your syntax error. If statements need parentheses in javascript.
let accessGranted;
let message;
function checkPassword(passwordCorrect) {
if (passwordCorrect) {
accessGranted = true;
message = "Welcome to the admin panel!";
}
else {
accessGranted = false;
message = "Wrong password."
}
}
checkPassword(true)
console.log('Access Granted:', accessGranted);
console.log('Message:', message);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
phantom = require 'phantom'
phantom.create (ph) ->
ph.createPage (page) ->
page.open "http://www.google.com", (status) ->
console.log "opened google? ", status
page.evaluate (-> document.title), (result) ->
console.log 'Page title is ' + result
ph.exit()
I tried using this website but it doesn't seem to be very accurate. It has returns everywhere. http://js2coffee.org/#coffee2js
Update: After a second look, it does seem that some of these returns are spurious/redundant. That is because Coffeescript just always returns the result of the last statement in the function (so that you can save the return keyword), even in cases where you would not have returned anything in Javascript (the compiler cannot know your intention here). That may be unnecessary, but there is also no harm in it, if no one was using the return value anyway. If it is somehow important to return "nothing", you'd can explicitly do that, too.
You can just compile it, to see what it results in:
var phantom;
phantom = require('phantom');
phantom.create(function(ph) {
return ph.createPage(function(page) {
return page.open("http://www.google.com", function(status) {
console.log("opened google? ", status);
return page.evaluate((function() {
return document.title;
}), function(result) {
console.log('Page title is ' + result);
return ph.exit();
});
});
});
});
It has returns everywhere.
Well, every function you define there has one return.
One of the prime motivators for Coffeescript is to be able to write all those callback functions with less boilerplate.
Either way, the compiler is "accurate".
var phantom = require('phantom');
phantom.create(function(ph)) {
ph.createPage(function(page) {
page.open("http://www.google.com", function(status) {
console.log("opened google? ", status);
page.evaluate(function() { return document.title; }, function() {
console.log('Page title is ' + result);
ph.exit()
}
});
});
});