0

当我有一个带有yes和no按钮的jquery对话时,我将如何在后端运行一个方法来发送电子邮件,如下所示:

<script language="javascript" type="text/javascript">
        $(document).ready(function () {
            $("#dialog").dialog({
                autoOpen: false,
                modal: true
            });
        });

        $(".confirmLink").click(function (e) {
            e.preventDefault();
            var targetUrl = $(this).attr("href");

            $("#dialog").dialog({
                buttons: {
                    "Yes": function () {
                        $(this).dialog("close"),
                        SendEmail(),
                    window.location.href = targetUrl;
                    },
                    "No": function () {
                        $(this).dialog("close");
                    }
                }
            });

            $("#dialog").dialog("open");
        });
    </script>

<a class="confirmLink" href="emailsend.aspx"></a>
     <div id="dialog" title="Confirmation Required">
                    <p>
                        Do you want to send an email?</p>
                </div>
4

1 回答 1

3

您必须通过 ajax 与后端进行通信,然后后端将发送电子邮件;有点像这样:

function SendEmail(email, content)
{
    var data = "email=" + escape(email) + "&content=" + escape(content);
    $.ajax({
        url: "sendemail.asp",
        type: 'POST',
        data: data,
        success: function(data){
            alert("Hurray");
        },
        error: function() {
            alert("Oh noes! It went wrong");
        }
    }); 
}
于 2012-10-12T11:13:04.343 回答