Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for refresh an element #298

Open
enesislam opened this issue Sep 16, 2022 · 3 comments
Open

Support for refresh an element #298

enesislam opened this issue Sep 16, 2022 · 3 comments

Comments

@enesislam
Copy link

enesislam commented Sep 16, 2022

To refresh a div I can do this in JQuery:

     $("#yourDiv").load(" #yourDiv > *"); 

But I couldn't do that without JQuery. Can you help me?

@Abbondanzo
Copy link
Contributor

How do you mean "refresh a div". Could you provide a practical example of this? I was thinking you could theoretically replace the contents of one div with another or reassign inner HTML with something like this:

<div id="a">Content A</div>
<div id="b">Content B</div>
$("#a").load("#b");

But that doesn't appear to have any effect because no content is being specified/loaded

@enesislam
Copy link
Author

Here is the example
I refresh the profile picture div when a user changes his/her profile picture. I want to do this with JavaScript. and I hope you can add this section into the page

$.ajax({
            method: "POST",
            url: "{% url 'account_profile' %}",
            processData: false,
            contentType: false,
            mimeType: "multipart/form-data",
            data: data,
            success: function(a) {
            let object = JSON.parse(a) 
                $('#avatar').attr('src', object['pp'])
                $( "#avatar" ).load(window.location.href + " #avatar" );  //!  I might not need Jquery
            },
        })
    ```

@Abbondanzo
Copy link
Contributor

Abbondanzo commented Sep 28, 2022

Here is the example I refresh the profile picture div when a user changes his/her profile picture. I want to do this with JavaScript. and I hope you can add this section into the page

$.ajax({
            method: "POST",
            url: "{% url 'account_profile' %}",
            processData: false,
            contentType: false,
            mimeType: "multipart/form-data",
            data: data,
            success: function(a) {
            let object = JSON.parse(a) 
                $('#avatar').attr('src', object['pp'])
                $( "#avatar" ).load(window.location.href + " #avatar" );  //!  I might not need Jquery
            },
        })
    ```

In this particular example, the line prior to $.load should be the one refreshing the profile picture. This line changes the source attribute of the image element:

$('#avatar').attr('src', object['pp'])

Unless if the src URL is not changing. If that's the case, what you're looking for is a cache busting mechanism. That can be achieved by appending an extraneous query parameter onto the URL similar to the following (and by itself is a niche usage of what load can do):

$('#avatar').attr('src', `${object['pp']}?t={new Date().getTime()}`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants