将 html 转换为纯文本 jquery .ajax

convert html to plain text jquery .ajax

请找到下面的 jQuery 代码。完美发送电子邮件,但我在电子邮件中看到一大堆代码 (HTML)。我想将 #righthtml() 输出转换为 text()。我该怎么做?

$(document).ready(function () {
    $('.confirm_button').click(function () {
        var student_name = $.trim($('#student_name').val());
        var student_contact = $.trim($('#student_contact').val());
        var student_email = $.trim($('#student_email').val());
        var right = $('#right').html();

        if (student_name.length < 3 || student_contact.length < 8 || student_email.length < 4)
        {
            $('#sendfail').attr('title', 'Sending Failed!').text('Please Enter valid information. All fields are required').dialog({
                buttons: {
                    'Ok': function () {
                        $(this).dialog('close');
                        $location.reload(true);
                    }
                },
                closeOnEscape: true,
                draggable: false,
                resizable: false,
                modal: true
            });
        }
        else
        {
            var objAjaxRequestData = {
                'student_name': student_name,
                'student_contact': student_contact,
                'student_email': student_email,
                'right': right
            };
            $.ajax({
                type: 'POST',
                url: 'send-select-university.php',
                data: objAjaxRequestData,
                success: function () {
                    $('#sendsuccess')
                            .attr('title', 'Message sent successfully')
                            .text('Your message has been sent. We will be in touch soon')
                            .dialog({
                                buttons: {
                                    'Ok': function () {
                                        $(this).dialog('close');
                                        window.location = "http://www.ankooverseas.com";
                                    }
                                },
                                closeOnEscape: true,
                                draggable: false,
                                resizable: false,
                                modal: true
                            });
                },
                error: function () {
                    alert('Oops request sending failed. Please check your internet connection and try again');
                }
            });
        }

    });
});

你需要更换

var right=$('#right').html();

var right=$('#right').text();

根据您的意见,我认为您最好使用以下代码在格式化视图中显示所选项目:

var right = "";
$("#shortlist_univs").children().each(function (i, univ) { // iterate over all universities and add them to the output variable in a list-like view.
  right += $(univ).text() + "\n"
});