没有Form标签的Ajax Jequery Post&不刷新 [英] Ajax Jequery Post without Form tag & without refresh

查看:59
本文介绍了没有Form标签的Ajax Jequery Post&不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面可以通过ajax jQuery发布数据,而无需刷新无表单标签. N通过小吃店验证.

I have a page to post data via ajax jquery without refresh an without form tag. N validate via snackbar.

我知道使用jQuery和AJAX可以做到这一点,但是我对这些语言中的一种并没有真正的经验.有人知道如何解决这个问题吗?

I know that this is possible using jQuery and AJAX, but I'm not really experienced in one of these languages. Anyone got an idea how to solve this?

其按钮功能:

<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:

this my 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数据库.

please help here. two days spent for this error. I cannot Post the data to mysql database..

推荐答案

我通过删除if(isset($_POST['tombolsimpan'])){& }在.php进程上

i fix by delete if(isset($_POST['tombolsimpan'])){ & } on .php process

这篇关于没有Form标签的Ajax Jequery Post&amp;不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆