Script doesn't show image for users
2 posters
Page 1 of 1
Script doesn't show image for users
URL: https://cozylife.forumotion.com/t3-test
When you scroll down this page (as logged user), you can see that Admin image is still the same as default one (selected from image upload) but it doesn't load the image set from edit field in user's profile.
It doesn't load for admin user. But when I am signed in as Admin, I can see for myself and for test user.
Script:
How can this work for admin normally but fails for user? It does load second avatar for himself, but not for admin, at all.
For testing purposes ask me in PM for user login credentials.
When you scroll down this page (as logged user), you can see that Admin image is still the same as default one (selected from image upload) but it doesn't load the image set from edit field in user's profile.
It doesn't load for admin user. But when I am signed in as Admin, I can see for myself and for test user.
Script:
- Code:
$(document).ready(function() {
let listOfUsers = document.querySelectorAll('.post-aside');
listOfUsers.forEach((item, index) => {
let listOfBackgroundUsers = document.querySelectorAll('.avatar-big img');
let address = item.querySelector('.post-author-name a').getAttribute('href');
$.ajax({
url: address,
method: "GET",
data: 'dl#field_id1',
dataType: "html",
success: function(data) {
let div = document.createElement('div');
div.innerHTML = data;
let secondAvatar = div.querySelector('dl#field_id1 dd div.field_editable.invisible input')?.getAttribute('value');
console.log(secondAvatar);
if (secondAvatar != "") {
$(listOfBackgroundUsers[index]).attr("src", secondAvatar);
}
}
});
});
});
How can this work for admin normally but fails for user? It does load second avatar for himself, but not for admin, at all.
For testing purposes ask me in PM for user login credentials.
Last edited by The Raven on August 31st 2023, 9:56 pm; edited 1 time in total
Guest- Guest
Re: Script doesn't show image for users
Good morning!
Guests do not have access to the user profile on the forums. The code doesn't access the link where the information should be downloaded and because of that AJAX request doesn't work.
Guests do not have access to the user profile on the forums. The code doesn't access the link where the information should be downloaded and because of that AJAX request doesn't work.
Razor12345- Support Moderator
- Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine
Re: Script doesn't show image for users
I know that one. I am talking about the user itself, somebody is a member, but not administrator. Let me send you credentials as a user in PM
Guest- Guest
Razor12345- Support Moderator
- Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine
Re: Script doesn't show image for users
I use that code. I mean, why it works for admin, but not for a user? How is that possible? I used the same script you gave me for cover image with changes for AwesomeBB.
Guest- Guest
Re: Script doesn't show image for users
Who told you that simply copying code can solve all problems?
My code was written for a different version of the forum and for a different purpose.
The code loads data correctly but processes it incorrectly.
My code was written for a different version of the forum and for a different purpose.
The code loads data correctly but processes it incorrectly.
Razor12345- Support Moderator
- Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine
Re: Script doesn't show image for users
Razor12345 wrote:Who told you that simply copying code can solve all problems?
My code was written for a different version of the forum and for a different purpose.
The code loads data correctly but processes it incorrectly.
As I mentioned it, I altered the code for AwesomeBB, not just copy/paste. It does take image URL of avatar. It does place it for administrator perfectly. When logged as user, it works only for himself, but not for administrator. For some reason values I get are "undefined".
Guest- Guest
Re: Script doesn't show image for users
As I said, this line has the wrong path to the profile field value.
This field path is only available to the administrator for all profiles. If we are talking about an ordinary user, this path is available only for his profile.
To test it, you can use
in the success method
Try this:
- Code:
let secondAvatar = div.querySelector('dl#field_id1 dd div.field_editable.invisible input')?.getAttribute('value');
This field path is only available to the administrator for all profiles. If we are talking about an ordinary user, this path is available only for his profile.
To test it, you can use
|
Try this:
- Code:
let secondAvatar = div.querySelector('dl#field_id4 dd div.field_uneditable img')?.getAttribute('src');
Razor12345- Support Moderator
- Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine
Re: Script doesn't show image for users
Razor12345 wrote:As I said, this line has the wrong path to the profile field value.
- Code:
let secondAvatar = div.querySelector('dl#field_id1 dd div.field_editable.invisible input')?.getAttribute('value');
This field path is only available to the administrator for all profiles. If we are talking about an ordinary user, this path is available only for his profile.
To test it, you can usein the success method
- Code:
console.log(div)
Try this:
- Code:
let secondAvatar = div.querySelector('dl#field_id4 dd div.field_uneditable img')?.getAttribute('src');
I tried this today and it didn't work. I get undefined values.
Guest- Guest
Re: Script doesn't show image for users
I fixed it.
- Code:
$(document).ready(function() {
let listOfUsers = document.querySelectorAll('.post-aside');
listOfUsers.forEach((item, index) => {
let listOfBackgroundUsers = document.querySelectorAll('.avatar-big img');
let address = item.querySelector('.post-author-name a').getAttribute('href');
$.ajax({
url: address,
method: "GET",
data: 'dl#field_id1',
dataType: "html",
success: function(data) {
let div = document.createElement('div');
div.innerHTML = data;
let secondAvatar = div.querySelector('dl#field_id1 dd .field_uneditable img').src;
if (secondAvatar != "") {
$(listOfBackgroundUsers[index]).attr("src", secondAvatar);
}
}
});
});
});
Guest- Guest
Re: Script doesn't show image for users
Problem solved & topic archived.
|
Similar topics
» My Forum Widgets Doesnt Show Up
» Show/hide script not working
» Show/Hide Widgets Script
» Show/Hide Widgets Script
» how to add background image in this script
» Show/hide script not working
» Show/Hide Widgets Script
» Show/Hide Widgets Script
» how to add background image in this script
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum