Is there a way to run a script that check's if #username-input is
empty then run this script:
document.getElementById('login-button').addEventListener('click', function ()
{
var name = document.getElementById('username-input').value;
document.getElementById('username').innerHTML = 'Welcome ' + name;
document.getElementById('username-input').remove();
document.getElementById('password-input').remove();
document.getElementById('login-button').remove();
}, false);
EDIT
And if #username-input and #password-input is empty
an alert is popping up and say that instead of running the script
alert('username or password can't be blank')
it seems that you aren't using JQuery so this would do it.
if (document.getElementById('username-input').value != "") {
document.getElementById('login-button').addEventListener('click', function () {
var name = document.getElementById('username-input').value;
document.getElementById('username').innerHTML = 'Welcome ' + name;
document.getElementById('username-input').remove();
document.getElementById('password-input').remove();
document.getElementById('login-button').remove();
}, false);
}
//define the on success function.
var onSuccess = function () {
document.getElementById('login-button').addEventListener('click', function ()
{
var name = document.getElementById('username-input').value;
document.getElementById('username').innerHTML = 'Welcome ' + name;
document.getElementById('username-input').remove();
document.getElementById('password-input').remove();
document.getElementById('login-button').remove();
}, false);
}
//Get the username and password.
var userName = document.getElementById('username-input').value;
var userName = document.getElementById('password-input').value;
//validate the input
//This if statement will check if either userName or password is null, 0, "", or undefined.
if (userName && password) {
onSuccess();
}
else {
alert("username or password can't be blank");
}
Just use an if statement to check if the div is empty.
if($('#username-input').text() != '') {
document.getElementById('login-button').addEventListener('click', function ()
{
var name = document.getElementById('username-input').value;
document.getElementById('username').innerHTML = 'Welcome ' + name;
document.getElementById('username-input').remove();
document.getElementById('password-input').remove();
document.getElementById('login-button').remove();
}, false);
}
And for the username and password check.
if($('#username-input').text() != '' || $('#password-input').text() != '') {
alert('username or password can't be blank')
}
Related
I have a Google Script that I've inherited and I'm looking to update it to reflect current requirements.
Currently it fires off 2 emails to a participant and sponsor using data in a Google Sheet. I've tried combining it so that section 'Now email for each doc' sends an email to the participant and cc's the sponsor.
I've gotten as far as updating the code from :
var sendTo = row[EMAIL];
to :
var sendTo = row[EMAIL] + " , " + sponsors;
and removing section '2. Personal Case' which doesn't solve the cc query.
I've tried amending the existing code to add in the additional parameters as stated on https://developers.google.com/apps-script/reference/mail/mail-app but can't seem to get it to work in the code below.
// Now email for each doc
var email = getAppraiseeEmail();
if(email && email.body) {
email.body = email.body.replaceAll('%doctitle1%', bTitle)
/*.replaceAll('%doctitle2%', pTitle)
.replaceAll('%doctitle3%', dTitle)
.replaceAll('%doctitle4%', dpTitle)
.replaceAll('%link1%', bFile.getUrl())
.replaceAll('%link2%', pFile.getUrl())
.replaceAll('%link3%', dFile.getUrl())
.replaceAll('%link4%', dpFile.getUrl())*/
.replaceAll('%link5%', child.getUrl())
.replaceAll('%name%', row[NAME]);
var sendTo = row[EMAIL];
if(sendTo && sendTo!=='') {
email.recipient = sendTo;
sendAnEmail(email);
}
} else {
throw Error('missing email configuration (Business Case)');
}
// 2. Personal Case
if(sponsors.length > 0) {
var emailRev = getSponsorEmail();
if(emailRev && emailRev.body) {
emailRev.body = emailRev.body.replaceAll('%doctitle1%', bTitle)
/*.replaceAll('%doctitle2%', pTitle)
.replaceAll('%doctitle3%', dTitle)
.replaceAll('%doctitle4%', dpTitle)
.replaceAll('%link1%', bFile.getUrl())
.replaceAll('%link2%', pFile.getUrl())
.replaceAll('%link3%', dFile.getUrl())
.replaceAll('%link4%', dpFile.getUrl()) */
.replaceAll('%link5%', child.getUrl())
.replaceAll('%name%', row[NAME]);
var sendTo = sponsors.join(',');
if(sendTo && sendTo!=='') {
emailRev.recipient = sendTo;
sendAnEmail(emailRev);
}
} else {
throw Error('missing email configuration (sponsor)');
}
} // end if re sponsors
row[NOTES] = 'Files created & shared, ' + timestamp;
} catch(e) {
console.error(e);
row[NOTES] = 'An error occurred (' + e + '), ' + timestamp;
}
function getAppraiseeEmail() {
var email = {};
email.body = getConfig('email01');
email.subject = getConfig('subject01');
return email;
}
function getSponsorEmail() {
var email = {};
email.body = getConfig('email02');
email.subject = getConfig('subject02');
return email;
}
function sendAnEmail(email) {
var options = { noReply: true, htmlBody: email.body };
MailApp.sendEmail(email.recipient, email.subject, null , options);
}
Ideally it should fire out the email from section 'Now email for each doc' and cc the sponsors in section '2. Personal Case'.
Thanks in advance!
UPDATE 15/07/19
I've updated the code to the below which now works:
// Now email for each doc
var email = getAppraiseeEmail();
if(email && email.body) {
email.body = email.body.replaceAll('%doctitle1%', bTitle)
.replaceAll('%link5%', child.getUrl())
.replaceAll('%name%', row[NAME]);
var CC = row[SPONSORS]
var sendTo = row[EMAIL]
if(sendTo && sendTo!=='') {
email.recipientTO = sendTo;
email.CC = CC;
sendAnEmail(email);
}
} else {
throw Error('missing email configuration (Business Case)');
}
row[NOTES] = 'Files created & shared, ' + timestamp;
} catch(e) {
console.error(e);
row[NOTES] = 'An error occurred (' + e + '), ' + timestamp;
}
function getAppraiseeEmail() {
var email = {};
email.body = getConfig('email01');
email.subject = getConfig('subject01');
return email;
}
function sendAnEmail(email) {
var options = { noReply: true, htmlBody: email.body, cc: email.CC };
MailApp.sendEmail(email.recipientTO, email.subject, null , options);
}
In my Node application I have used get and post request. Using get just renders the page and using post insert data into MySQL database. Data is inserted properly but after post gets called and alert fade away very quickly.
This is my code from app.js:
app.get('/Associate', routes.Associate);
app.get('/addAssociate',routes.addAssociate);
app.post('/addAssociate',routes.postAssociate);
This is my code from routes.js:
Associate: function(req, res) {
sess = req.session;
var name = req.session.user;
var username = 'SELECT first_name from user_info where email_id=?';
if (sess.user) {
console.log('\n--------------------- Associate ----------------------');
var db = req.app.get('db')();
var id = req.query['id'];
// var newsquery='SELECT * from associate_info';
var assoquery = 'SELECT associate_id,doctor_id,CONCAT(initial," ",first_name," ",middle_name," ",last_name) As Name,qualification,address_line1,city,state,pincode,email_id,contact_no from associate_info ';
var redirect = 'Associate_Listing';
async.parallel({
one: function(callback) {
db.query(assoquery, function(error, rows, fields, next) {
console.log("length-\t", rows.length);
callback(error, rows);
});
},
two: function(callback) {
db.query(username, [name], function(error, rows, fields, next) {
// console.log(rows.length);
console.log(rows);
callback(error, rows);
});
}
},
function(error, results) {
var totalNews = results.one.length;
for (var i = 0; i < results.one.length; i++) {
if (!(results.one[i].views > 0) || results.one[i].views == null)
results.one[i].views = 0;
results.one[i].ids = i + 1;
// if(!(results.one[i].views>0))
// results.one[i].views=0;
}
// console.log("--------",results.one[0].id);
res.render(redirect, {
error: JSON.stringify(1),
from_period: 0,
to_period: 0,
state: JSON.stringify("All States"),
user2: "Dr" + " " + JSON.parse(JSON.stringify(results.two[0]["first_name"])),
user: JSON.parse(JSON.stringify(req.session.user)),
Associate: results.one,
str_journal: JSON.stringify(results.one),
user_type_id: req.session.user_type_id,
totalJournals: JSON.stringify(totalNews)
});
});
} else {
res.redirect('/login');
}
},
// addJournal:function(req,res){
addAssociate: function(req, res) {
console.log('\n-------------------- addAssociate ----------------------\n');
var name = req.session.user;
var db = req.app.get('db')();
var username = 'SELECT first_name from user_info where email_id=?';
if (req.session.user) {
async.parallel({
one: function(callback) {
db.query(username, [name], function(error, rows, fields, next) {
console.log("length-\t", rows.length);
callback(error, rows);
});
}
},
function(error, results) {
res.render('addAssociate', {
user: JSON.parse(JSON.stringify(req.session.user)),
// cases : results.one,
user2: "Dr" + " " + JSON.parse(JSON.stringify(results.one[0]["first_name"])),
user_type_id: req.session.user_type_id,
// totalNews :JSON.stringify(totalNews)
})
});
} else {
res.redirect('/login');
// res.redirect('addAssociate');
}
},
postAssociate: function(req, res) {
console.log('\n-------------------- postAssociate ----------------------\n');
var db = req.app.get('db')();
// res.send('Username: ' + req.body.doctorName);
// var title = req.body.title;
// var created =req.body.created;
// initial : req.body.doctorName,
// var id=1;
// var dateArray=created.split('/');
// var finalDate=""+dateArray[2]+"/"+dateArray[1]+"/"+dateArray[0];
// var date1=new Date(finalDate);
var initial;
var first_name;
var middle_name;
var last_name;
var qualification;
var address_line1;
var address_line2;
var city;
var state;
var pincode;
var email_id;
var contact_no;
var Uname = req.session.user;
var post = {
initial: req.body.initial,
first_name: req.body.first_name,
middle_name: req.body.middle_name,
last_name: req.body.last_name,
qualification: req.body.qualification,
address_line1: req.body.address_line1,
address_line2: req.body.address_line2,
city: req.body.city,
state: req.body.state,
pincode: req.body.pincode,
email_id: req.body.email_id,
contact_no: req.body.contact_no,
status: 1,
};
console.log('--------------------' + initial)
console.log(initial);
console.log(post);
db.query('SELECT * from user_info where email_id= ? ', [Uname], function(error, rows, fields) {
if (error) {
console.log(error);
} else {
console.log('name------------' + Uname);
console.log('rows---------' + rows.length);
for (var i in rows) {
console.log('----------hhh---' + rows[i].doctor_id);
}
db.query('INSERT INTO associate_info SET doctor_id=' + rows[i].doctor_id + ', creation_date=CURRENT_TIMESTAMP(), ? ', post, function(error, result) {
console.log('inside if');
if (error) {
console.log(error);
res.status(200).send({
success: 3,
error: error
});
return;
}
console.log('Associate added successfully.');
});
}
});
},
this is jquery ajax code
$(document).ready(function() {
$("#save").click(function() {
var initial = $("#doctorName").val();
var first_name = $("#firstName").val();
var middle_name = $("#middleName").val();
var last_name = $("#lastName").val();
var qualification = $("#qualification").val();
var address_line1 = $("#address1").val();
var address_line2 = $("#address2").val();
var city = $("#city").val();
var state = $("#state").val();
var pincode = $("#pincode").val();
var email_id = $("#email").val();
var contact_no = $("#mobile").val();
var dr = /^[a-zA-Z]+\.$/;
var alphaExp = /^[a-zA-Z]+$/;
var zipexp = /^[0-9]{1,6}$/;
var mobileexp = /^(\+91-|\+91|0)?\d{10}$/;
var emailexp = /^[A-Z0-9_'%=+!`#~$*?^{}&|-]+([\.][A-Z0-9_'%=+!`#~$*?^{}&|-]+)*#[A-Z0-9-]+(\.[A-Z0-9-]+)+$/i;
// Returns successful data submission message when the entered information is stored in database.
var dataString = 'initial=' + initial + '&first_name=' + first_name + '&middle_name=' + middle_name + '&last_name=' + last_name + '&qualification=' + qualification + '&address_line1=' + address_line1 + '&address_line2=' + address_line2 + '&city=' + city + '&state=' + state + '&pincode=' + pincode + '&email_id=' + email_id + '&contact_no=' + contact_no;
if (initial == '' || first_name == '' || middle_name == '' || last_name == '' || qualification == '' || address_line1 == '' || address_line2 == '' || city == '' || state == '' || pincode == '' || email_id == '' || contact_no == '') {
alert("Please Fill All Mandatory Fields");
return false;
} else if (!initial.match(alphaExp) && !initial.match(dr)) {
alert("please insert valid initial");
$("#doctorName").val('');
document.getElementById('doctorName').focus();
return false;
} else if (!first_name.match(alphaExp)) {
alert("please insert valid first name");
$("#firstName").val('');
document.getElementById('firstName').focus();
return false;
} else if (!middle_name.match(alphaExp)) {
alert("please insert valid middle name");
$("#middleName").val('');
document.getElementById('middleName').focus();
return false;
} else if (!last_name.match(alphaExp)) {
alert("please insert valid last name");
$("#lastName").val('');
document.getElementById('lastName').focus();
return false;
} else if (!pincode.match(zipexp) || pincode.length != 6) {
alert("please insert valid pincode");
$("#pincode").val('');
document.getElementById('pincode').focus();
return false;
} else if (!email_id.match(emailexp)) {
alert("please insert email id");
$("#email").val('');
document.getElementById('email').focus();
return false;
} else if (!contact_no.match(mobileexp)) {
alert("please insert valid contact no");
$("#mobile").val('');
document.getElementById('mobile').focus();
return false;
} else {
// AJAX Code To Submit Form.
$.ajax({
type: "post",
url: "/addAssociate",
// contentType: 'application/json',
data: dataString,
cache: false,
success: function(data) {
console.log("data-----------" + data);
alert("hi");
}
});
}
// return;
// return false;
});
});
I want to display an alert after data inserted successfully into database.
Just Try the Following to make some delay.
jQuery :
$.ajax({
url:'path-to-process',
type:'POST',
data:{},
success:function(){
// Content to Display on Success.
setTimeout(function () {
// Content to Display on Success with delay.
}, 800);
}
});
Here, the "setTimeout()" will provide some specified time delay for display your content.
Have a Nice Day !
http://jsbin.com/jatuju/edit?js,output
If you are using the plan old JavaScript,you can using the XMLHttpRequest status code to determine whether is success or not
I'm having a problem locating where my problem is. I'm using PubNub for realtime messaging and the example project is using ECC (elliptical curve cryptography) encrypted messaging.
Every thing in the file works(animation, channel presence, etc.) except for sending the message. Every time I hit send I get this message:
Here is my chat-app.js file:
(function() {
if (typeof(user) === 'undefined') {
return;
}
var output = document.getElementById('output'),
input = document.getElementById('input'),
picture = document.getElementById('picture'),
presence = document.getElementById('presence'),
action = document.getElementById('action'),
send = document.getElementById('send');
var channel = 'fun';
var keysCache = {};
var pubnub = PUBNUB.init({
subscribe_key: 'sub-c-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
publish_key: 'pub-c-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
uuid: user.name,
auth_key: user.gtoken,
ssl: true
});
function displayOutput(message) {
if(!message) return;
if(typeof(message.text) === 'undefined') return;
var html = '';
if ('userid' in message && message.userid in keysCache) {
var signature = message.signature;
delete message.signature;
var result = ecc.verify(keysCache[message.userid].publicKey, signature, JSON.stringify(message));
if(result) {
html = '<p><img src="'+ keysCache[message.userid].picture +'" class="avatar"><strong>' + keysCache[message.userid].name + '</strong><br><span>' + message.text + '</span></p>';
} else {
html = '<p><img src="images/troll.png" class="avatar"><strong></strong><br><em>A troll tried to spoof '+ keysCache[message.userid].name +' (but failed).</em></p>';
}
output.innerHTML = html + output.innerHTML;
} else {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/user/' + message.userid, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var res = JSON.parse(xhr.responseText);
keysCache[message.userid] = {
'publicKey': res.publicKey,
'name': res.name,
'artist': res.artist,
'picture': res.picture,
'id': res.id
}
displayOutput(message);
}
};
xhr.send(null);
}
}
function getHistory() {
pubnub.history({
channel: channel,
count: 30,
callback: function(messages) {
messages[0].forEach(function(m){
displayOutput(m);
});
}
});
}
pubnub.subscribe({
channel: channel,
restore: true,
connect: getHistory,
disconnect: function(res){
console.log('disconnect called');
},
reconnect: function(res){
console.log('reconnecting to pubnub');
},
callback: function(m) {
displayOutput(m);
},
presence: function(m){
if(m.occupancy === 1) {
presence.textContent = m.occupancy + ' person online';
} else {
presence.textContent = m.occupancy + ' people online';
}
if((m.action === 'join') || (m.action === 'timeout') || (m.action === 'leave')){
var status = (m.action === 'join') ? 'joined' : 'left';
action.textContent = m.uuid + ' ' + status +' room';
action.classList.add(m.action);
action.classList.add('poof');
action.addEventListener('animationend', function(){action.className='';}, false);
}
}
});
function post() {
var safeText = input.value.replace(/\&/g, '&').replace( /</g, '<').replace(/>/g, '>');
var message = { text: safeText, userid: user.id };
var signature = ecc.sign(user.eccKey, JSON.stringify(message));
message['signature'] = signature;
pubnub.publish({
channel: channel,
message: message
});
input.value = '';
}
input.addEventListener('keyup', function(e) {
if(input.value === '') return;
(e.keyCode || e.charCode) === 13 && post();
}, false);
send.addEventListener('click', function(e) {
if(input.value === '') return;
post();
}, false);
})();
This error is coming from my ecc.js file
Uncaught TypeError: Cannot read property 'r' of undefined
However, I'm assuming the error is in the chat-app.js file because I didn't touch the ecc.js file. I got it from the project -- https://github.com/pubnub/auth-chat-demo
More info on ECC can be found here: https://github.com/jpillora/eccjs
According to your description, it looks like this line is giving you the error:
var signature = ecc.sign(user.eccKey, JSON.stringify(message));
So I am guessing you are not properly passing user.eccKey?
Do you have all the user data from oAuth (or any login auth)? or is the eccKey generated correctly upon the user sign-up?
Also, try include the non-minified version of ecc.js so you can track where the error is coming from more easily.
https://raw.githubusercontent.com/jpillora/eccjs/gh-pages/dist/0.3/ecc.js
I'm making a register/login form in javascript. User should enter information about himself and the computer should put that information into an array and remember it but it 'forgets' it every time I reload the page.
else {
document.cookie = email;
cookies[cookies.length] = document.cookie;
$('#error').text("Your registration is complete.");
break;
}
...more code
$('.btn').click(function() {
alert(cookies[cookies.length - 1]);
});
Any ideas to solve this? I have one more question. How can I check weather is an username alerady in use?
Here is the full js code:
var main = function() {
var people = [];
var cookies = [];
$('#register_email').val("");
$('#register_username').val("");
$('#register_password').val("");
$('#register2_password').val("");
function Person(username, email, password, repeat_password) {
this.username = username;
this.email = email;
this.password = password;
this.repeat_password = repeat_password;
}
$('#register').click(function() {
var username = $('#register_username').val();
var email = $('#register_email').val();
var password = $('#register_password').val();
var r_password = $('#register2_password').val();
if( email==="" || username==="" || password==="" || r_password==="") {
$('#error').text("You didn't fill everything");
}
else {
people[people.length] = new Person(username, email, password, r_password);
for(var key in people) {
//This should check weather this username was used before but I'm not really sure what to insert instead of "name"
if(people[people.length - 1].username === "name") {
$('#error').text("This username is already in use");
break;
}
else if(password !== r_password) {
$('#error').text("Passwords don't match");
break;
}
else {
document.cookie = email;
cookies[cookies.length] = document.cookie;
$('#error').text("Your registration is complete.");
break;
}
}
}
});
$('.btn').click(function() {
alert(cookies[cookies.length - 1]);
});
};
$(document).ready(main);
There is a js-fiddle live example in comments.
I've got two functions which both get the user_id of a user. One function gets the session user_id and the other function gets the id that's in the url like so: profile.html?id=123. Here's the code:
// get URL parameter (user_id)
function GetURLParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
// get URL parameter (user_id) function call
url_user_id = GetURLParameter('id');
alert("url user id = " + url_user_id);
// get SESSION user_id
function get_session_user_id() {
$.post( "http://localhost/snapll_back/account/session_user_id.php",
function(info) {
if(info != "Something went wrong. ERROR{1_RAI_ERROR}") {
session_user_id = info;
alert("session user id = " + session_user_id);
// hide the follow button if this me is owned by the viewer
if(session_user_id == url_user_id) {
$("#follow_button").hide();
}
// THE QUESTION ON S.O. IS ABOUT THIS IF STATEMENT
// give the url_user_id variable the value of the session_user_id variable if not set correctly via the URL
if(url_user_id == 'undefined' || url_user_id == "" || url_user_id == null) {
url_user_id = session_user_id;
}
}
else {
$('#warning').html(info).fadeIn(200);
setTimeout(function () {
window.location.href = "index.html";
}, 2000);
}
});
return false;
}
get_session_user_id();
So, what I need to do is to check if the variable 'url_user_id' is set. If not, the url_user_id should get the same value as the variable 'session_user_id'. However, for some reason, this doesn't happen. I have the if statement in the code above in this part:
if(url_user_id == 'undefined' || url_user_id == "" || url_user_id == null) {
url_user_id = session_user_id;
}
I use the url_user_id variable to get the username of the current profile the user is viewing. Here's the function that gets the username:
// get username function
function get_username() {
$.post( "http://localhost/snapll_back/account/username.php?id="+url_user_id,
function(info) {
if(info != "Something went wrong. ERROR{1_RAI_ERROR}") {
$("#main_header_username").html(info);
}
else {
$('#warning').html(info).fadeIn(200);
}
});
return false;
}
When I visit the page with the url like this: www.mywebsite.com/profile.php?id= (so if I specify no id in the URL) the variable url_user_id, which normally gets its value from the URL, should get the value of the variable session_user_id. Currently, I keep getting 'undefined' as the value of url_user_id and the if statement doesn't seem to notice that value to take action.
Who knows how I can fix this?
+=======================================================================================+
EDIT
I'm now able to give the url_user_id the right value, but my function get_username() can't access that value. My get_session_user_id function now looks like this:
// get SESSION user_id
function get_session_user_id() {
$.post( "http://localhost/snapll_back/account/session_user_id.php",
function(info) {
if(info != "Something went wrong. ERROR{1_RAI_ERROR}") {
session_user_id = info;
alert("session user id = " + session_user_id);
// if url_user_id is not defined by the URL give it the value of session_user_id
if(url_user_id == 'undefined' || url_user_id == "" || url_user_id == null) {
url_user_id = session_user_id;
alert("url user id = " + url_user_id);
}
// hide the follow button if this me is owned by the viewer
if(session_user_id == url_user_id) {
$("#follow_button").hide();
}
}
else {
$('#warning').html(info).fadeIn(200);
setTimeout(function () {
window.location.href = "index.html";
}, 2000);
}
});
return false;
}
It alerts url_user_id with the correct value when no id is specified in the URL, but the get_userame function still says 'undefined' when I alert it in that function. Why can't the get_username function get the most recent value of url_user_id?
It looks like you're calling get_username immediately, before get_session_user_id has had a chance to return.
Try doing this:
// get URL parameter (user_id)
function GetURLParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
// get URL parameter (user_id) function call
url_user_id = GetURLParameter('id');
// get SESSION user_id
function get_session_user_id() {
$.post( "http://localhost/snapll_back/account/session_user_id.php",
function(info) {
if(info != "Something went wrong. ERROR{1_RAI_ERROR}") {
session_user_id = info;
//alert("session user id = " + session_user_id);
// if url_user_id is not defined by the URL give it the value of session_user_id
if(url_user_id == 'undefined' || url_user_id == "" || url_user_id == null) {
url_user_id = session_user_id;
//alert("url user id = " + url_user_id);
}
// hide the follow button if this me is owned by the viewer
if(session_user_id == url_user_id) {
$("#follow_button").hide();
}
}
else {
$('#warning').html(info).fadeIn(200);
setTimeout(function () {
window.location.href = "index.html";
}, 2000);
}
// get username function call
get_username();
});
return false;
}
get_session_user_id();
// get username function
function get_username() {
//alert(url_user_id);
$.post( "http://localhost/snapll_back/account/username.php?id="+url_user_id,
function(info) {
if(info != "Something went wrong. ERROR{1_RAI_ERROR}") {
$("#main_header_username").html(info);
}
else {
$('#warning').html(info).fadeIn(200);
}
});
return false;
}
/*
* function calls
*/
// check session function call
check_session();
We've moved the call to get_username inside the success callback to your POST, but otherwise the code is the same.