传递到PHP URL时AJAX成功不起作用

时间:2018-06-26 10:54:48

标签: php jquery ajax

我的代码有问题,我正在使用AJAX处理该过程并传递给php文件...因此,让我们检查以下代码:

function srchVcr() {
        var vchrNum = $( "#vouchNum" ).val();

        $('#trAlert').remove();

        if(vchrNum == ""){

            $( "#vcr_Nbr" ).html("");
            $( "#vcr_Amt" ).html("");
            $( "#vcr_Status" ).html("");
            $( "#vcr_EffDate" ).html("");
            $( "#vcr_ExpDate" ).html("");
            $( "#vcr_Location" ).html("");
            $( "#vcr_Used" ).html("");
            $( "#vcr_NoCheck" ).html("");
            $( "#vcr_Cashier" ).html("");

            $('#vcrLogTbl tbody').remove();
            $('#vcrMstrTbl').prepend("<tr id='trAlert'><td colspan='3'><strong style='color:#FF0000'>Mohon Isi Voucher Number</strong></td></tr>");

        } else {

            var url = "/vouchercontrol/home.php";



            $.ajax({

                method      : "POST",
                dataType    : "json",
                url         : url,
                data        : {vchrNum:vchrNum},
                success     : function(umpanBalik){ 

                $('#trAlert').remove();

                $('#vcrLogTbl tbody').remove(); 
                $( ".progress2" ).hide();

                if(umpanBalik.vcr_Nbr){

                    $( "#vcr_Nbr" ).html(umpanBalik.vcr_Nbr);
                    $( "#vcr_Amt" ).html(umpanBalik.vcr_Amt);
                    $( "#vcr_Status" ).html(umpanBalik.vcr_Status);
                    $( "#vcr_EffDate" ).html(umpanBalik.vcr_EffDate);
                    $( "#vcr_ExpDate" ).html(umpanBalik.vcr_ExpDate);
                    $( "#vcr_Location" ).html(umpanBalik.vcr_Location);
                    $( "#vcr_Used" ).html(umpanBalik.vcr_Used);
                    $( "#vcr_NoCheck" ).html(umpanBalik.vcr_NoCheck);
                    $( "#vcr_Cashier" ).html(umpanBalik.vcr_Cashier);

                } else {

                    $( "#vcr_Nbr" ).html("");
                    $( "#vcr_Amt" ).html("");

                    $('#vcrMstrTbl').prepend("<tr id='trAlert'><td colspan='3'><strong style='color:#FF0000'>Data Voucher Tidak Ditemukan</strong></td></tr>");
                    $('#vcrLogTbl tbody').remove();

                } // tutup else umpanBalik.vcr_Nbr

                }, // tutup method success

                error: function(XMLHttpRequest, textStatus, errorThrown) {
                     alert("some error");
                  }

            }) // tutup ajax

        } // tutup else vchrNum

    } // tutup function

因此通过按钮调用函数 搜索

然后这是我的php请求:

if(isset($ _ POST ['vchrNum'])){

$vcrnum  = $_POST['vchrNum'];
$datavcr = array();

$qryvcr = "SELECT * FROM vcr_used WHERE voucherno = '".$vcrnum."'";
$sqlvcr = mysqli_query($link, $qryvcr);
$cekvcr = mysqli_num_rows($sqlvcr);

if($cekvcr > 0){

    while($row = mysqli_fetch_array($sqlvcr)){

        $datavcr['vcr_Nbr']     = $row['voucherno'];
        $datavcr['vcr_Amt']     = "";
        $datavcr['vcr_Status']  = "";
        $datavcr['vcr_EffDate'] = "";
        $datavcr['vcr_ExpDate'] = "";
        $datavcr['vcr_Location'] = $row['storename'];
        $datavcr['vcr_Used']     = $row['busidate'];
        $datavcr['vcr_NoCheck']  = $row['chk_num'];
        $datavcr['vcr_Cashier']  = $row['emplname'];
    }


} else {

    $datavcr['vcr_Nbr'] = "";

}

$json = json_encode($datavcr);
die($json); 

如果我填写了文本框并提交,则错误ajax发出的警报只会显示出来... 为什么ajax无法处理成功?

对不起,我的英语,希望您能理解我的意思...

谢谢。...

0 个答案:

没有答案