Script doesn't show image for users Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

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.
2 posters

    Script doesn't show image for users

    avatar
    Guest
    Guest


    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
    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

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


    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
    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

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


    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.
    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

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


    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".
    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

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


    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


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

        });

    });
    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15311
    Reputation : 1705
    Language : English,Greek
    Location : Greece

    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