【问题标题】:Sweetalert2: How to get textarea into ajax requestSweetalert2:如何让 textarea 进入 ajax 请求
【发布时间】:2019-11-28 09:55:30
【问题描述】:

抱歉,经过一个小时的尝试和搜索,我找不到解决方案。 我正在尝试将 sweetalert 的 textarea 输入获取到 ajax 请求中。

var 文本始终未定义。

像这样:

jQuery(document).ready(function(){
if(window.location !== "turnier-bearbeiten/*"){
            jQuery( "#loeschen" ).click(function() {                     
                        const { value: text } = Swal.fire({
                                        title: 'Achtung!',
                                        text: 'Bist du sicher, dass du das Turnier absagen möchtest? Es gibt kein zurück!',
                                        input: 'textarea',
                                        inputPlaceholder: 'Bitte begründe deine Absage. Alle Teilnehmer erhalten entsprechend diese Nachricht.',
                                        icon: 'warning',
                                        showCancelButton: true,
                                        cancelButtonText: 'Abbrechen',
                                        confirmButtonText: 'Turnier absagen!'
                        }).then((result) => {
                            alert (text);
                            if (text != null) {
                                        var url_string = window.location.href;
                                        var url = new URL(url_string);
                                        var turnier_id = url.searchParams.get("data_id");
                                        jQuery.ajax({
                                                type: "POST",
                                                dataType: "json",
                                                url: "../custom_scripts/turnier_loeschen.php",
                                                data: { turnier_id: turnier_id, nachricht:text },
                                                success: function(response){    
                                                            if (response.redirect) {

【问题讨论】:

  • 没有人可以提供帮助或建议?

标签: javascript ajax sweetalert sweetalert2


【解决方案1】:

使用 preConfirm 我让它以某种方式成功运行:

jQuery( "#turnier-loeschen" ).click(function() {                     
        const { value: text } = Swal.fire({
            title: 'Achtung!',
            text: 'Bist du sicher, dass du das Turnier absagen möchtest? Es gibt kein zurück!',
            input: 'textarea',
            inputPlaceholder: 'Bitte begründe deine Absage. Alle Teilnehmer erhalten entsprechend diese Nachricht.',
            icon: 'warning',
            showCancelButton: true,
            cancelButtonText: 'Abbrechen',
            confirmButtonText: 'Turnier absagen!',  
            preConfirm: () => {
                var id = document.getElementsByClassName("swal2-textarea");
                var value = id[0].value;
                if (value.length != 0) {
                    //alert (id[0].value); mache nichts
                } else { Swal.showValidationMessage('Du musst eine Begründung angeben, damit du das Turnier absagen kannst!') }
            }
        }).then((result) => {
            //alert (result.value);
            if (result.value != null) {
                var url_string = window.location.href;
                var url = new URL(url_string);
                var turnier_id = url.searchParams.get("data_id");
                var text = result.value;
                jQuery.ajax({
                    type: "POST",
                    dataType: "json",
                    url: "../scripts/loeschen.php",
                    data: { turnier_id: turnier_id, nachricht:text },

等等……

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    相关资源
    最近更新 更多