有没有办法解决Ajax和CI错误500

时间:2019-04-04 08:42:43

标签: php jquery ajax codeigniter

我的ajax发送帖子在控制台中显示内部服务器错误500。该URL似乎不起作用,即使它是正确的。我有另一个有效的代码,但现在似乎无法正常工作。

我尝试过更改url,复制了整个ajax脚本(它是从一个外部源中下载的,只是使用$ this-> load-> view('my script')加载到html中)

My Javascript
$(document).on("click", "#confirm", function(event){

              var upName = $("#upName").val();

              var fname = $("#fname").val();
              var mname = $("#mname").val();
              var lname = $("#lname").val();
              var cntctNum = $("#cntctNum").val();
              var email = $("#emailAd").val();
              var pc = $("#pcNum").val();
              var upId = $("#upId").val();

              if (fname == '' || mname == '' || lname == '' || cntctNum == '' || email == '' || pc == '' || upId == '') 
              {
                alert("Please fill in the necessary fields");
              }
              else
              {
                $.ajax({//start of ajax function

                    type: "POST",
                    url: "<?php echo base_url('tbbCon/regMem');  ?>",
                    data: 
                          {
                              fname : fname,
                              mname : mname,
                              lname : lname,
                              cntctNum : cntctNum,
                              email : email,
                              pc : pc,
                              upId : upId
                          },
                    success: function(html)
                    {
                      if(html == 'success'){
                        alert("Success");
                        window.location.href = '<?php echo base_url('tbbCon'); ?>';
                      }else{
                        $("#result").html(html);
                      }
                    }

                  //end of ajax function
                  });
              }

              //alert("My Upline is: " + upName + "\nMy Upline's bpCode is: " + upId + "\nMy Placement is: " + Placement);



            });// this is the end of the click function
my forms
    <!-- Modal -->
    <div id="regMem" class="modal fade" role="dialog">

      <div class="modal-dialog modal-xl">

        <!-- Modal content-->
        <div class="modal-content">

          <div class="modal-header">

            <h4 class="modal-title">Register Member</h4>
            <button type="button" class="close" data-dismiss="modal">&times;</button>

          </div>

          <div class="modal-body">

            <form>
              <div class="container">
                <div class="row">
                  <div class="col-sm-2" style="border-style: solid;">
                    <!-- EMPTY -->
                  </div>

                  <div class="col-sm-8" style="border-style: solid;">
                    <h3 align="center">PERSONAL INFO</h3>

                    <div class="row" >
                      <div class="col">
                        <div class="input-group mb-3">
                          <div class="input-group-prepend">
                            <span class="input-group-text">Full Name:</span>
                          </div>

                          <input type="text" class="form-control" name="fname" id="fname" placeholder="First Name">

                          <input type="text" class="form-control" name="mname" id="mname" placeholder="Middle Name">

                          <input type="text" class="form-control" name="lname" id="lname" placeholder="Last Name">
                        </div>
                      </div>
                    </div>

                    <div class="row">
                      <div class="col">
                        <div class="form-inline">
                          <div class="input-group mb-3">
                            <div class="input-group-prepend">
                              <span class="input-group-text">Contact No.</span>
                            </div>

                            <input type="text" class="form-control" name="cntctNum" id="cntctNum" placeholder="Enter Contact No." maxlength="12">
                          </div>
                        </div>
                      </div>

                      <div class="col">
                        <div class="form-inline">
                          <div class="input-group mb-3">
                            <input type="text" class="form-control" name="emailAd" id="emailAd" placeholder="Email Address">

                            <div class="input-group-append">
                              <span class="input-group-text">@example.com</span>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

                    <br>

                    <div class="row">
                      <div class="col">
                        <label>Sponsor Name:</label>

                        <input type="text" class="form-control" name="upName" id="upName"placeholder="Enter Upline Name" disabled>
                        <input type="text" class="form-control" name="upId" id="upId" hidden>
                      </div>

                      <div class="col">
                        <label>Placement Code:</label>

                        <input type="text" class="form-control" name="pc" id="pcNum"placeholder="Enter Placement No." disabled>
                      </div>
                    </div>

                    <br>

                    <form class="form-inline">
                      <button type="button" id="cancel" class="btn btn-danger" style="width: 100px;">Cancel</button>
                      <button type="button" id="confirm" class="btn btn-primary" style="width: 100px;">Confirm</button>
                    </form>

                    <br>
                  </div>

                  <div class="col-sm-2" style="border-style: solid;">
                    <!-- EMPTY -->
                    <div id="result">

                    </div>
                  </div>
                </div>
              </div>
            </form>

        </div>

      </div>

    </div>
</div>
controller basically need to access regMem()
<?php

    class tbbCon extends CI_Controller
    {
        public function index()
        {
            $this->load->model("accsModel");//load model
            $data = $this->session->all_userdata();
            if (empty($data['logged']) !== false) 
            {
                $this->load->view('Login');
            }
            else
            {
                $data['downs'] = $this->accsModel->getBps();//call model's function
                $this->load->view("tbb", $data);
            }

        }

        public function tbl()
        {
            $this->load->model("accsModel");
            $data['downs'] = $this->accsModel->getBps();
            $this->load->view("table", $data);
        }

        public function regMem()
        {
            $this->load->model('accsModel');

            //id for db
            $bps_id = $this->getGuid();

            //this gets the names
            $fname = ucwords($this->input->post('fname'));//getting POST data from ajax
            $mname = ucwords($this->input->post('mname'));
            $lname = ucwords($this->input->post('lname'));

            //Fname------------------------------------------------------------------------
            $fnameArr = explode(" ", $fname);
            $fnameForBpId = '';
            foreach ($fnameArr as $fnames) 
            {
                $fnameForBpId .= substr($fnames, 0);
            }
            //Fname------------------------------------------------------------------------

            $concatName = $fnameForBpId.substr($mname, 0, 1).substr($lname, 0, 1);
            $bps_BpId = $this->accsModel->checkBps($concatName);
            //this gets the number
            $cntctNum = $this->input->post('cntctNum');
            //this gets the email
            $email = $this->input->post('email');
            //this gets the placement codes
            $pc = $this->input->post('pc');
            //this gets the upline ID
            $upId = $this->input->post('upId');
            $bpclass = 1;

            //this is the users account
            $id = $this->getGuid();
            $uname = substr($fname, 0, 1).substr($mname, 0, 1).substr($lname, 0, 1);
            $pass = uniqid();

            $regBps = array(`id` => $bps_id,
                         `bpID` => $bps_BpId,
                         `pc` => $pc,
                         `up` => $ipId,
                         `tmLdr` => 0,
                         `fName` => $fname,
                         `mName` => $mname,
                         `lName` => $lname,
                         `contactNo` => $cntctNum,
                         `status_id` => 1,
                         `bpclass_id` => $bpclass );

            $RegLog = array(`id` => $id,
                         `uname` => $uname ,
                         `pwd` => $pass,
                         `bps_id` =>  $bps_id);

            $this->accsModel->insertReg($regBps);
            $this->accsModel->insertReg($RegLog);
        }



        public function getGuid()
        {
            if (function_exists('com_create_guid') === true)
            {
                return trim(com_create_guid(), '{}');
            }

                return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
        }
    }

?>

0 个答案:

没有答案