0

On my site I've a button that when is clicked open a dialog with a form already populated for send an e-mail. In this form I have a button called "invia" to send mail, the mail are sent correctly, what does not work it is closeing dialog after send e-mail. Here attacched my code:

Thanks in advance for help.

$("#invio_mail").live("click", function() { 
if (m=="") //that's to prevent multiple dialog opening
{
 $.post("./php/testo_mail_xml.php",
 {contratto:contratto, piatta:piatta, testo:"stampa_login"},
 function(xml)
 {
 if ($(xml).find("status").text()==1)
 {
 $("#ris_dial").load("./schemi/sch_mail.htm");
 delay( function() { //that's a function for delay population
 scorriDati(xml, "forMail"); //that's function for populate
 }, 500);
 var dm = {
 modal: true,
 height: 'auto',
 width: 'auto',
 title: "<span class='ui-icon ui-icon-info'></span> Invio Mail",
 closeOnEscape: false,
 buttons: {"Invia": function() {
 $.post("./php/mail.php",
 {dati:$("#forMail").serialize()},
 function(xml)
 {
 if ($(xml).find("status").text()==1)
 {
 //var opt={close:true};
 //$("#ris_dial").dialog(opt);
 $(this).dialog("close"); //this is not wrking code
 }
 else
 $(this).append($(xml).find("errore").text());
 },"xml"
 );
 }
 }
 };
 $("#ris_dial").dialog(dm);
 }
 else
 {
 $("#ris_dial").empty().append($(xml).find("errore").text());
 $("#ris_dial").dialog(dialogError);
 }
 },
 "xml"
 );
 m++;
}
});
Devjosh
6,4824 gold badges41 silver badges61 bronze badges
asked Jun 21, 2011 at 8:24
2
  • you want to close dialog or dont it's not clear from your question Commented Jun 21, 2011 at 8:27
  • @Devjosh: Thanks for answering I want when I get status==1 ( email correctly send) that dialog close. Commented Jun 21, 2011 at 8:31

1 Answer 1

2

the context of this changes inside of $.post()

save this before you call post:

var $this = $(this);

and change your call to close to be:

$this.dialog("close")
answered Jun 21, 2011 at 8:29
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.