簡體   English   中英

在 ajax post 請求中收到 500 內部服務器錯誤

[英]Getting 500 internal server error on ajax post request

我在ajax發布請求中收到 500 內部服務器錯誤。 我正在本地主機上測試它,我的路線也准確。

我已經為這個調用編寫了路由,而不是在 url 中調用控制器名稱和方法。

我的代碼如下,任何幫助將不勝感激。

$('#personal-info').click(function(){
    //  Var paramstr = $("#personal-info").serialize();
     var form_data = {            //repair
            firstname: $('#firstname').val(),
            lastname: $('#lastname').val(),
            fathername: $('#fathername').val(),
            cnic: $('#cnic').val(),
            gender: $('#gender').val(),
            marital_status: $('#marital_status').val(),
            day_of_birth: $('#day_of_birth').val(),
            month_of_birth: $('#month_of_birth').val(),
            year_of_birth: $('#year_of_birth').val(),
            email: $('#email').val(),
            phone: $('#phone').val(),
            postal_code: $('#postal_code').val(),
            country_id: $('#country_id').val(),
            state_id: $('#state_id').val(),
            industry_id: $('#industry_id').val(),
            experienc_level: $('#experienc_level').val(),
            current_salary: $('#current_salary').val(),
            expected_salary: $('#expected_salary').val(),
            salary_currency: $('#salary_currency').val(),
            address: $('#address').val(),
            skype: $('#skype').val(),
            professional_summary: $('#professional_summary').val(),
            face_book: $('#face_book').val(),
            twitter: $('#twitter').val(),
            linkedin: $('#linkedin').val(),
            blog: $('#blog').val(),
            website: $('#website').val(),
            // created_at: $('#created_at').val()
        };


    $.ajax({
        url: "<?php echo base_url('add_personal_info'); ?>",//repair
        type: 'POST',
        data: form_data, // $(this).serialize(); you can use this too
        success: function(msg) {
              alert("success..!! or any stupid msg");
        }

   });
   return false;

});

我的PHP代碼是:

public function add_candidate_personal_info(){

  $candidate = $this->input->post();
  $this->load->model('common_model');
  // $this->load->library('form_validation');
  $this->load->helper('common_helper');
  $this->load->model('User_model');

  $this->form_validation->set_rules('firstname', 'First Name', 'required');
  $this->form_validation->set_rules('lastname', 'Last Name', 'required');
  $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[candidate.email]');
  $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
  if (empty($_FILES['userfile']['name']))
  {
      $this->form_validation->set_rules('userfile', 'File Upload', 'required');
  }

  if($this->form_validation->run()==FALSE){
    $formError = validation_errors();
    $this->data['errorMessage'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
    $this->load->view('front/user/candidate/add', $this->data);
   // redirect('register_candidate');
  }
  else {
    $personal_data = array(
        'firstname' => $this->input->post('firstname'),
        'lastname' => $this->input->post('lastname'),
        'father_name' => $this->input->post('father_name'),
        'cnic' => $this->input->post('cnic'),
        'gender' => $this->input->post('gender'),
        'marital_status' => $this->input->post('marital_status'),
        'day_of_birth' => $this->input->post('day_of_birth'),
        'month_of_birth' => $this->input->post('month_of_birth'),
        'year_of_birth' => $this->input->post('year_of_birth'),
        'email' => $this->input->post('email'),
        'phone' => $this->input->post('phone'),
        'postal_code' => $this->input->post('postal_code'),
        'country_id' => $this->input->post('country_id'),
        'state_id' => $this->input->post('state_id'),
        'industry_id' => $this->input->post('industry_id'),
        'experienc_level' => $this->input->post('experienc_level'),
        'current_salary' => $this->input->post('current_salary'),
        'expected_salary' => $this->input->post('expected_salary'),
        'salary_currency' => $this->input->post('salary_currency'),
        'address' => $this->input->post('address'),
        'skype' => $this->input->post('skype'),
        'professional_summary' => $this->input->post('professional_summary'),
        'face_book' => $this->input->post('face_book'),
        'twitter' => $this->input->post('twitter'),
        'linkedin' => $this->input->post('linkedin'),
        'blog' => $this->input->post('blog'),
        'website' => $this->input->post('website'),
        'created_at' => date('Y-m-d H:i'),
    );

     if ($this->common_model->insert('candidate_resume_profile', $personal_data)) {
            $this->ajaxResponse['status'] = 200;
            $this->ajaxResponse['message'] = $this->message->success('Candidate Personal Information is Successfully Added');
            $this->ajaxResponse['data'] = '';
            exit(json_encode($this->ajaxResponse));
        } else {
            $this->ajaxResponse['status'] = 500;
            $this->ajaxResponse['message'] = $this->message->error('Internal Error');
            $this->ajaxResponse['data'] = '';
            exit(json_encode($this->ajaxResponse));
        }

  }
}

我認為您可以查看瀏覽器的信息,或者您可以查找 Nginx/apache 的 error.log 在 Linux 中您可以使用命令 locate error.log 來查找您的 error.log

這可能是因為您的 php 基本文件權限。 嘗試更改權限:

  • 將您的“base_url('add_personal_info')”文件和所有其他基本文件權限更改為 644。
  • 將他們的文件夾權限更改為 755。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM