Codeigniter jquery表单提交没有刷新

时间:2016-01-14 04:35:26

标签: jquery mysql ajax codeigniter

我制作了此表单,但它并不想重定向到结果页面。

CONTROLLER

   function succeded()
{
        $this->load->view('wifi/header');
        $this->load->view('wifi/result-post-wifi');
        $this->load->view('wifi/footer');
}       
    function wifi_sign_up()                
{
            $tableName = "wifi_regs";
    $data['datetime_registrasi']        = date('Y-m-d H:i:s',now($this->input->post('datetime_registrasi')));               
            $data['nomor_registrasi']           = $this->wifi_model->getRegid($this->input->post('regid'));
            $data['username']                   = $this->input->post('inputUsername');
    $data['password']                   = md5($this->input->post('inputPassword'));
            $data['nama_lengkap']               = $this->input->post('inputNamaLengkap');
    $data['nomor_hp']                   = $this->input->post('inputNomorHP');
    $data['email']                      = $this->input->post('inputEmail');
    $data['paket']                      = $this->input->post('inputPaket');
    $data['metode_bayar']               = $this->input->post('inputMetodePembayaran');
            $data['jml_transfer']               = $this->input->post('inputPaket')+$this->wifi_model->getKodeRegistrasi($this->input->post('kode_registrasi'));            
            $data['bank_transfer']              = $this->input->post('inputBankPembayaran');
    $data['kode_registrasi']            = $this->wifi_model->getKodeRegistrasi($this->input->post('kode_registrasi'));
    $data['status_registrasi']          = $this->wifi_model->getStatusRegistrasi($this->input->post('status_registrasi'));
            $data['status_transfer']            = $this->wifi_model->getStatusTransferWifi($this->input->post('status_transfer'));


            if($this->wifi_model->insert_data($tableName, $data))
            {
                header("Content-type: application/json");
                header("HTTP/1.1: 200"); 
                header("status: 200");
                header("message : Register Berhasil");
                echo "{\"data\":" .json_encode($data). "}";
            }
        redirect('wifi/result-post-wifi', $data);                

MODEL

   public function insert_data($tableName, $data) {
     return $this->db->insert($tableName, $data);
   }

查看

                          <div id="result-post-wifi"></div>                              
                            <form role="form" id="form-wifi" class="form-wifi" onsubmit="return registrasi('wifi');">
                                <div class="form-group">
                                    <label class="sr-only" for="form-username">Username</label>
                                    <input type="text" name="username_wifi" placeholder="Username..." class="form-username form-control" id="username_wifi" required>
                                </div>
                                <div class="form-group">
                                    <label class="sr-only" for="form-password">Password</label>
                                    <input type="password" name="password_wifi" placeholder="Password..." class="form-password form-control" id="password_wifi" required>
                                </div>
                                            <div class="form-group">
                                    <label class="sr-only" for="form-password_2">Confirm Password</label>
                                    <input type="password" name="password_2_wifi" placeholder="Confirm Password..." class="form-password_2 form-control" id="password_2_wifi" required>
                                </div>
                                            <div class="form-group">
                                    <label class="sr-only" for="form-nama">Nama Lengkap</label>
                                    <input type="text" name="nama_lengkap_wifi" placeholder="Nama Lengkap..." class="form-username form-control" id="nama_lengkap_wifi" required>
                                </div>
                                            <div class="form-group">
                                    <label class="sr-only" for="form-nomor_hp">Nomor HP</label>
                                    <input type="text" name="nomor_hp_wifi" placeholder="Nomor HP..." class="form-nomor-hp form-control" id="nomor_hp_wifi" required>
                                </div>
                                <div class="form-group">
                                    <label class="sr-only" for="form-email">Email</label>
                                    <input type="text" name="email_wifi" placeholder="Email..." class="form-email form-control" id="email_wifi" required>
                                </div>
                                <div class="form-group">
                                    <label class="sr-only" for="form-email">Paket</label>
                                                      <select name="paket_wifi" id="paket_wifi" class="form-control" required>
                                                        <option value="" selected="selected">Pilih Paket</option>
                                                        <option value="1">Paket 1</option>
                                                        <option value="2">Paket 2</option>
                                                        <option value="3">Paket 3</option>
                                                      </select>
                                            </div>
                                            <div class="form-group">
                                    <label class="sr-only" for="form-pembayaran-wifi">Metode Pembayaran</label>
                                                      <select name="pembayaran_wifi" id="pembayaran_wifi" class="form-control" onChange="set_metode_pembayaran(this.value, 'wifi')" required>
                                                        <option value="1" selected="selected">Transfer Bank</option>
                                                        <option value="2">Cash/ Tunai</option>
                                                      </select>
                                            </div>
                                <div class="form-group" id="metode_pembayaran_wifi">
                                    <label class="sr-only" for="form-metode-pembayaran">Paket Wifi</label>
                                                      <select name="bank_pembayaran_wifi" id="bank_pembayaran_wifi" class="form-control">
                                                        <option value="" selected="selected">Pilih Bank</option>
                                                        <option value="1">Bank 1</option>
                                                        <option value="2">Bank 2</option>
                                                        <option value="3">Bank 3</option>
                                                        <option value="4">Bank 4</option>
                                                      </select>                                                 
                                            </div>
                                    <button type="submit" class="btn"><strong> REGISTRASI SEKARANG </strong></button>
                            </form>
                </div>
                    </div>
                </div>

RESULT

                                <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Nomor Registrasi </label>
                                                    <div class="form-email info-label"><?php  echo $nomor_regisrasi ?></div>       
                                            </div>
                                            <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Status Registrasi </label>
                                                    <div class="form-email info-label"><?php  echo $status_regisrasi ?></div>                                                 
                                            </div>
                                            <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Username </label>
                                                    <div class="form-email info-label"><?php  echo $username ?></div>                                                  
                                            </div>
                                            <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Nama Lengkap  </label>
                                                    <div class="form-email info-label"><?php echo $nama_lengkap ?></div>                                                  
                                            </div>
                                            <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Nomor HP </label>
                                                    <div class="form-email info-label"><?php echo $nomor_hp ?></div>                                                  
                                            </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Email</label>
                                                    <div class="form-email info-label"><?php echo $email ?></div>                                                  
                                            </div> 
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Paket</label>
                                                    <div class="form-email info-label"><?php echo $paket ?></div>                                                  
                                            </div>
                                            <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Jumlah Transfer</label>
                                                    <div class="form-email info-label"><?php echo $jml_transfer ?></div>                                                
                                            </div>
                                            <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Pembayaran Melalui</label>
                                                    <div class="form-email info-label"><?php echo $metode_bayar ?></div>                                                
                                            </div>
                                            <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Nomor Rekening</label>
                                                    <div class="form-email info-label"><?php echo $nomor_rekening ?></div>                                                  
                                            </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-xs-5 control-label">Atas Nama</label>
                                                    <div class="form-email info-label"><?php echo $atas_nama ?></div>                                                  
                                            </div>
                                            <div class="form-group"> 
                                    <label for="inputEmail3" class="col-xs-5 control-label">Informasi Registrasi</label>
                                                    <label class="btn btn-default" onclick="window.open( 'http://www.domain.com', '_blank' )"><strong> DETAIL </strong></label>                                                  
                                            </div>
                                            <div class="form-group">
                                                    <button class="btn btn-default" onclick="window.open( 'http://www.domain.com', '_blank' )"><strong> BAYAR SEKARANG </strong></button>
                                            </div>
                            </form>
                </div>
                    </div>
             </div>

SCRIPT

function registrasi(jp, regid)
{    
            if(regid === undefined)
            {
                    regid = '';
            }
$('#result-post-' + jp).html('<div class="alert alert-info">Mengirimkan Data Registrasi ...</div>');
    var sd = "";
                if(jp == 'wifi' || jp == 'webservice')
        {
            sd = "inputUsername=" + $('#username_' + jp).val() + "&inputPassword=" + $('#password_' + jp).val() + "&inputNamaLengkap=" + $('#nama_lengkap_' + jp).val() + "&inputNomorHP=" + $('#nomor_hp_' + jp).val() + "&inputEmail=" + $('#email_' + jp).val() + "&inputPaket=" + $('#paket_' + jp).val() + "&inputBankPembayaran=" + $('#bank_pembayaran_' + jp).val() + "&inputMetodePembayaran=" + $('#pembayaran_' + jp).val();
        }

            if(sd.length > 0)
    {
    $.ajax({
                dataType     : "json",
        type     : "POST",
        url      : "wifi/sign_up",
        data     : sd + "&jp=" + jp + "&regid=" + regid,
        success  : function(res){ set_result(res, jp) ; },
            error        : function()
                            { 
                            $('#result-post-' + jp).html('<div class="alert alert-warning">Gagal mengirim data Registrasi.</div>'); 
                            }, 
                timeout: 50000          
    });
        }
    return false;

     }
    function set_result(res, jp)
{
    $('#result-post-' + jp).removeAttr('style');        
    if(res.status == 200 || res.status == 102)
    {
        $('#result-post-' + jp).html('');
        $('#result-post-' + jp).removeAttr('style');
        if(res.data == undefined)
        {
            $('#result-post-' + jp).html(res.message);              
        }
        else
        {
            $('#form-' + jp).attr({style : 'display:none;'})
            $('#result-post-' + jp).html(res.message + res.data);
        }
    }
    else if(res.status == 101)
    {
        $('#result-post-' + jp).html(res.message);
    }
    else
    {
        $('#result-post-' + jp).html(res.message);
    }       
}

function open_form(jp)
{
    $('#form-' + jp)[0].reset();
    $('#form-' + jp).removeAttr('style');
    $('#meto?de_pembayaran_' + jp).removeAttr('style');
    $('#result-post-' + jp).html('');           
}

我会非常感谢任何帮助

0 个答案:

没有答案