0

I want to happen is that the class="profile-pic" will refresh/reload before or on the dialog closes because the image source changes.

This is my code:

$('.change-profile-pic').click(updateProfilePicture);
function updateProfilePicture(){
    $('#dialog').dialog({
        resizable:false,
        modal:true,
        width:225,
        buttons: {
            'Upload':function(){
                $('#upload-image').ajaxForm({ 
                        target: '.new-profile-pic'
                }).submit();
            },
            'Done':function(){
                $.ajax({
                    url: 'update-profile-pic.php',
                    type: 'post',
                    data: { file_path: $('.new-profile-pic img').attr('src') },
                    success: function(data) {
                        if(data == 'Success'){
                            $('#dialog').dialog('close');
                        }
                    }
                });
            }
        }
    });

HTML To be reloaded:

<p class="profile-pic ">
                    <a href="#"><img class="change-profile-pic ui-corner-all" src="<?php echo $user['user_profile_path']; ?>" alt=""></a>
                </p>

HTML form:

<div title="Change profile picture" id="dialog" class="dialog-change-profile-pic">
            <div class="new-profile-pic">

            </div>
            <form id="upload-image" enctype="multipart/form-data" action="upload-image.php" method="post">
                <input type="hidden" name="MAX_FILE_SIZE" value="100000">
                <input class="profile-pic-name" name="uploadedfile" type="file">
            </form>
        </div>
7
  • What should contain #loadthis after the reload? Commented Sep 24, 2012 at 8:44
  • You can refresh the div instead of reload Commented Sep 24, 2012 at 8:44
  • an image, i have to do something to it Commented Sep 24, 2012 at 8:44
  • What exactly do you mean by 'reload'? What should happen with the element? Commented Sep 24, 2012 at 8:45
  • 1
    You're going to have to be more specific in your question Commented Sep 24, 2012 at 8:45

2 Answers 2

1

You can write up the close event function which fires as soon as the close event fires..

<p class="profile-pic ">
                    <a href="#"><img class="change-profile-pic ui-corner-all" src="<?php echo $user['user_profile_path']; ?>" alt=""></a>
                </p>

close: function(event, ui) { 
    // Change the src attribute here with the newer source.. That should do 
 }

You can also use the beforeClose event

beforeClose: function(event, ui) { 

}
Sign up to request clarification or add additional context in comments.

Comments

0

Why is the image src wrapped in a PHP tag? Couldn't that just be static HTML? Your browser most likely has the image cached so if the image changes on the server side and you just want to reload it then you could do something like

$('.goButton').click(function() {
    $('#loadThis' img)[0].src = 'resources/default-male.png?' + Math.random();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.