1 回答

TA貢獻1853條經驗 獲得超6個贊
在下面的代碼中,我已經在內部傳遞了 textarea 的值function(result)
,然后我習慣了result.value
訪問 textarea 的值并將其傳遞給 ajax 調用。
演示代碼:
$('#sad').on('click', function() {
const sad = $('#sad').val();
const {
value: text
} = Swal.fire({
title: '<strong>Lass uns mehr erfahren</strong>',
input: 'textarea'
}).then(function(result) {
//chcking if user have type something in textbox
if (result.value) {
//printing in console
console.log(result.value)
$.ajax({
type: "POST",
url: "feedback.php", //===PHP file name and directory====
data: {
sad: sad,
values: result.value //<-sending textarea value
},
success: function(data) {
console.log(data);
//Success Message == 'Title', 'Message body', Last one leave as it is
Swal.fire({
icon: 'success',
title: "Danke!",
showConfirmButton: false,
timer: 3000
});
},
error: function(data) {
//Error Message == 'Title', 'Message body', Last one leave as it is
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Something went wrong!'
})
}
});
}
if (text) {
$.ajax({
type: "POST",
url: "feedback.php",
data: {
'text': text
}
})
}
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<button id="sad">Click</button>
然后,您需要使用 php 獲取在 ajax 中傳遞的值$_POST['values']
。
- 1 回答
- 0 關注
- 157 瀏覽
添加回答
舉報