Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

javascript - Sweetalert2:如何将textarea放入ajax请求(Sweetalert2: How to get textarea into ajax request)

sorry but after a hour of trying and searching i couldnt find a solution.(抱歉,经过一个小时的尝试和搜索,我找不到解决方案。)

I am trying to get the textarea input of a sweetalert into a ajax request.(我正在尝试将sweetalert的textarea输入转换为ajax请求。) The var text is always undefined.(var文本始终是未定义的。) Like this:(像这样:) 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) {   ask by Michael H. translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With preConfirm i got it to work successfully somehow:(使用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 }, and so on...(等等...)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...