如何使用jquery重新加载特定的html标签?

时间:2012-09-24 08:42:08

标签: jquery html

我想要发生的是class="profile-pic"将在对话框关闭之前或之后刷新/重新加载,因为图像源会发生变化。

这是我的代码:

$('.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要重新加载:

<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表单:

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

2 个答案:

答案 0 :(得分:1)

你可以写下close事件函数,一旦close事件触发就会触发..

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

您还可以使用beforeClose事件

beforeClose: function(event, ui) { 

}

答案 1 :(得分:0)

为什么图像src包装在PHP标签中?难道不能只是静态HTML吗?您的浏览器很可能已缓存图像,因此如果图像在服务器端发生更改而您只是想重新加载它,那么您可以执行类似

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