Сообщение Ajax Jequery без тега формы и без обновления

У меня есть страница для отправки данных через jQuery без обновления без тега формы. N проверить через закусочную.

Я знаю, что это возможно с помощью jQuery и AJAX, но я не очень опытен на одном из этих языков. Кто-нибудь понял, как это решить?

его функция кнопки:

<input type="text" id="nikpemohon"> <input type="text" id="namapemohon"> <button id="tombolsimpan" onclick="validate()"></button>` 

здесь мои js:

 function validate() { var regExnamapemohon = /^[a-zA-Z .'-]+$/; var values = { 'nikpemohon': document.getElementById('nikpemohon').value, 'namapemohon': document.getElementById('namapemohon').value, }; if(document.getElementById('nikpemohon').value == "" || document.getElementById('nikpemohon').value == null || document.getElementById('nikpemohon').value == undefined || document.getElementById('nikpemohon').value.length < 16 ) { //get the snackbar var notification = document.querySelector('.mdl-js-snackbar'); //creating data for snackbar notification var data = { message: 'Isi NIK dengan benar. Contoh: 6108011234567890', timeout: 4000 } //pushing the notification to the screen notification.MaterialSnackbar.showSnackbar(data); document.getElementById('nikpemohon').focus(); } else if (document.getElementById('namapemohon').value == "" || document.getElementById('namapemohon').value == null || document.getElementById('namapemohon').value == undefined || !regExnamapemohon.test(document.getElementById('namapemohon').value) ) { //get the snackbar var notification = document.querySelector('.mdl-js-snackbar'); //creating data for snackbar notification var data = { message: 'Isi Nama Lengkap hanya dengan huruf abjad saja, tanpa Penulisan Gelar. Contoh: Matius, Markus atau Darius', timeout: 4000 } //pushing the notification to the screen notification.MaterialSnackbar.showSnackbar(data); document.getElementById('namapemohon').focus(); } else { $.ajax({ url: "ktp_post.php", type: "POST", data: values, }); } } 

это мой ktp_post.php:

 if(isset($_POST['tombolsimpan'])){ $nikpemohon = strtoupper($_POST['nikpemohon']); $namapemohon = strtoupper($_POST['namapemohon']); $sql = $con->query("INSERT INTO katimpus (nikpemohon, namapemohon)Values('{$nikpemohon}', '{$namapemohon}')");} 

пожалуйста, помогите здесь. два дня, потраченные на эту ошибку. Я не могу отправить данные в базу данных mysql.

Вы использовали правильное значение для своей кнопки. Попробуйте вот так:

<form method='post'> <input type="text" id="nikpemohon"> <input type="text" id="namapemohon"> <input type="button" id="tombolsimpan" value="tombolsimpan" onclick="validate()"/> </form>

i исправить удалением if(isset($_POST['tombolsimpan'])){ & } в .php процессе