Dialog: using load function the close function doesn't work

Dialog: using load function the close function doesn't work

Hello everybody,
 
I'm using dialog from jquery.  I load the content with the load jquery function, it's work correctly until I want to close the window with ' $(this).dialog('close')'. The dialog is not closed. When I close with the button on the title of the dialog, this one is closed properly !
 
Here is the code:
  1. $("#finishTaskDialog").load(urlFinishTask).dialog({

    autoOpen: true,

    resizable: false,

    width:560,

    height:300,

    modal: false,

    overlay: {

    backgroundColor: '#000',

    opacity: 0.5

    },

    buttons:{

    'Mark as finished': function(){
  2. // do some stuff

    $(this).dialog('close');

    });

    },

    'Cancel': function() {

    $(this).dialog('close');

    }

    },

    });

    Thanks in advance for yout help
      Jamila