The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Script doesn't show image for users

2 posters

Go down

Solved Script doesn't show image for users

Post by Guest August 31st 2023, 9:19 am

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.

Script doesn't show image for users Screen76

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
avatar
Guest
Guest


Back to top Go down

Solved Re: Script doesn't show image for users

Post by Razor12345 August 31st 2023, 10:20 am

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.


Script doesn't show image for users Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Solved Re: Script doesn't show image for users

Post by Guest August 31st 2023, 10:31 am

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
avatar
Guest
Guest


Back to top Go down

Solved Re: Script doesn't show image for users

Post by Razor12345 August 31st 2023, 2:33 pm

Another path to the profile field

Code:
let secondAvatar = div.querySelector('dl#field_id1 dd div.field_editable.invisible input')?.getAttribute('value');

Script doesn't show image for users Scree337


Script doesn't show image for users Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Solved Re: Script doesn't show image for users

Post by Guest August 31st 2023, 2:50 pm

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.
avatar
Guest
Guest


Back to top Go down

Solved Re: Script doesn't show image for users

Post by Razor12345 August 31st 2023, 2:57 pm

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.


Script doesn't show image for users Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Solved Re: Script doesn't show image for users

Post by Guest August 31st 2023, 3:05 pm

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".
avatar
Guest
Guest


Back to top Go down

Solved Re: Script doesn't show image for users

Post by Razor12345 August 31st 2023, 3:37 pm

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 use
Code:
console.log(div)
in the success method

Try this:

Code:
let secondAvatar = div.querySelector('dl#field_id4 dd div.field_uneditable img')?.getAttribute('src');



Script doesn't show image for users Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Solved Re: Script doesn't show image for users

Post by Guest August 31st 2023, 3:42 pm

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 use
Code:
console.log(div)
in the success method

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.
avatar
Guest
Guest


Back to top Go down

Solved Re: Script doesn't show image for users

Post by Guest August 31st 2023, 9:54 pm

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);
                }
            }
        });

    });

});
avatar
Guest
Guest


Back to top Go down

Solved Re: Script doesn't show image for users

Post by skouliki August 31st 2023, 11:46 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules
skouliki
skouliki
Manager
Manager

Female Posts : 15397
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum