how to get member username with js?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

how to get member username with js?

Post by D Oliveira » 2019-05-31 18:11

hello, how to get member username with js? if you use the automatic value built in appgini whenever you call $j.val() it returns "" and I need it to return the username value, any ideas?

Thank you.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: how to get member username with js?

Post by jsetzer » 2019-05-31 21:49

If you use a field with that automatic value it should become a static control div and not an input. This means you cannot use .val() method. Try .text() instead:

var user = $j("created_by").text();

Regards,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: how to get member username with js?

Post by D Oliveira » 2019-05-31 22:02

jsetzer wrote:
2019-05-31 21:49
If you use a field with that automatic value it should become a static control div and not an input. This means you cannot use .val() method. Try .text() instead:

var user = $j("created_by").text();

Regards,
Jan

you sir are a genius, well deserved title/badge. one more question, how do you verify that the user name matches the text extracted from that field?

That reference should be accessible to all appgini users like the select2 tweaks and .reload features. thank you!

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: how to get member username with js?

Post by D Oliveira » 2019-05-31 23:01

user udayvatturi posted somewhere the solution, here it is:

Code: Select all


Ajax Call

var url1="getMemberInfo.php"; 
jQuery.ajax({
url: url1,
dataType: 'json',
success:function(response){
//alert(response); //display memberinfo['username']

if( $j('#createdby').text() == response ){
			console.log('here')
								
}
}

});

getMemberInfo.php
<?php
$curr_dir = dirname(__FILE__);
include("{$curr_dir}/defaultLang.php");
include("{$curr_dir}/language.php");
include("{$curr_dir}/lib.php");

$mi = getMemberInfo();
echo json_encode($mi['username']);
?>


User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: how to get member username with js?

Post by D Oliveira » 2019-06-01 01:10

D Oliveira wrote:
2019-05-31 23:01
user udayvatturi posted somewhere the solution, here it is:

Code: Select all


Ajax Call

var url1="getMemberInfo.php"; 
jQuery.ajax({
url: url1,
dataType: 'json',
success:function(response){
//alert(response); //display memberinfo['username']

if( $j('#createdby').text() == response ){
			console.log('here')
								
}
}

});

getMemberInfo.php
<?php
$curr_dir = dirname(__FILE__);
include("{$curr_dir}/defaultLang.php");
include("{$curr_dir}/language.php");
include("{$curr_dir}/lib.php");

$mi = getMemberInfo();
echo json_encode($mi['username']);
?>

also you wanna add that to your tablename-dv.js if you're trying to accomplish the same:

Code: Select all

jQuery('#update').hide();

//or 

jQuery('#update').show();

Post Reply