简体   繁体   English

从中获取价值 <div> 元素,选择收件人,通过Ajax(jQuery)将其通过电子邮件发送给收件人,并显示确认框

[英]Get value from a <div> element, choose recipient, send it via Ajax (jQuery) to a recipient via email and show confirmation box

I want to get a text from a div#main, send the text via Ajax jQuery to a php file from where I wil send it via email. 我想从div#main中获取文本,通过Ajax jQuery将文本发送到php文件,然后从那里通过电子邮件发送文本。

The user can choose the recipient of the from a multiple radio buttons choices on the site. 用户可以从站点上的多个单选按钮中选择收件人。

After I send the data to the PHP file I want to do some styles (eg remove a class, etc..). 在将数据发送到PHP文件之后,我想做一些样式(例如,删除类等)。

So far I have this, can you tell me if it is right? 到目前为止,我有这个,你能告诉我是否正确吗?

$(document).ready(function(){

    $('#submit').click(function(){
        $.ajax({
            type: 'POST',
            url: 'email.php',
            email: { recipient: $('input[type=radio]:checked').attr("value")},
            data: { content: $('#main').text()},
            success: function()
            {
                $("#email").removeClass("active");
            }

        });
    });

});

PS: I dont have the PHP file yet, I want just to figure out if my Ajax solution above is the right way to do what I've described. PS:我还没有PHP文件,我只是想弄清楚上面的Ajax解决方案是否是执行我所描述的正确方法。

All of the data that you want to send back to the server needs to be in the data property. 您要发送回服务器的所有数据都必须在data属性中。 Also, you probably want to use the val() method rather than accessing the value attribute directly. 另外,您可能希望使用val()方法,而不是直接访问value属性。

data: { content: $('#main').text(), recipient: $('input:radio:checked').val() },
$(document).ready(function(){    
    $('#submit').click(function(){
        $.post("email.php", { recipient: $('input[type=radio]:checked').val(), content: $('#main').text()}, function(){
              $("#email").removeClass("active");
        });    
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM