ajax将数据发布到控制器以获得成功,但我的模型未接收发布数据

时间:2016-05-21 10:28:03

标签: php jquery ajax

模型

public function __construct()   
{
    $this->load->database(); 

}
public function Set_Person_Persons($data)
{
    $this->db->db_set_charset("utf8");
    $this->db->insert('Persons',$data);
}

控制器

public function __construct()
{
    parent::__construct();
    $this->load->model('Persons_model');
}
public function Set_Person_C()
{
    $Name = $this->input->post('Name');
    $LName = $this->input->post('LName');
    $Company = $this->input->post('Company');
    $Category = $this->input->post('Category');
    $CategoryName =$this->input->post('CategoryName');
    $Address =$this->input->post('Address');
    $City =$this->input->post('City');
    $Phone =$this->input->post('Phone');
    $LastAction ='';
    $LastPayment ='';
    $About =$this->input->post('About');
    $Mobile =$this->input->post('Mobile');
    $Email =$this->input->post('Email');
    $PostalCode =$this->input->post('PostalCode');
    $BusinesCode =$this->input->post('BusinesCode');
    $RegisterDate =date('y-m-d');
           $data = array(
                'Name'=> $Name,
                'LName'=> $LName,
                'Company'=> $Company,
                'Category'=>$Category,
                'CategoryName'=> $CategoryName,
                'Address'=> $Address,
                'City'=> $City,
                'Phone'=> $Phone,
                'LastAction'=>'',
                'LastPayment'=>'',
                'About'=> $About,
                'Mobile'=> $Mobile,
                'Email'=> $Email,
                'PostalCode'=> $PostalCode,
                'BusinesCode'=> $BusinesCode,
                'RegisterDate'=> $RegisterDate
            );

    $Stats = $this->Persons_model->Set_Person_Persons($data);
    echo 'SuccessFully',$Stats;
}

的Javascript

function Set_Person(){
    var Name=$('#customer_register_name').val();
    var LName=$('#customer_register_lname').val();
    var Company=$('#customer_register_company').val();
    var Category=$('#customer_Category_Register').val();
    var CategoryName=$('#customer_Category_Register option:selected').text();
    var City=$('#customer_City_Register').val();
    var Email=$('#customer_register_email').val();
    var Phone=$('#customer_register_phone').val();
    var Mobile=$('#customer_register_mobile').val();
    var About=$('#customer_register_about').val();
    var BusinesCode=$('#customer_register_businescode').val();
    var PostalCode=$('#customer_register_postalcodevar').val();
    var Address=$('#customer_register_address').val();

    var post_url = "http://omixco.ir/FordoApps2/index.php/Persons_controller/Set_Person_C";
    $.ajax({
        type: "POST",
        url: post_url,
        data:{Name:Name, LName:LName, Company:Company, Email:Email, Category:Category,CategoryName:CategoryName, City:City,About:About,BusinesCode:BusinesCode,PostalCode:PostalCode,Address:Address,Phone:Phone,Mobile:Mobile},
        success: function(output)
        {
            var obj = JSON.parse(output);
            alert(obj);             
            if(output=='1')
            {
                $("#customer_register_Button").show();
                Get_All_Persons();

            }
        } //end success
     }); //end AJAX

}

视图

<div class="section row mbn">
    <div class="col-md-12 pl15">
        <div class="section row mb15">
            <div class="col-xs-4">
                <label for="name1" class="field prepend-icon">
                    <input type="text" name="customer_register_name" id="customer_register_name" class="event-name gui-input br-light light" placeholder="نام">
                    <label for="name1" class="field-icon"><i class="fa fa-user"></i></label>
                </label>
            </div>
            <div class="col-xs-4">
                <label for="name2" class="field prepend-icon">
                    <input type="text" name="customer_register_lname" id="customer_register_lname" class="event-name gui-input br-light light" placeholder="نام خانوادگی">
                    <label for="name2" class="field-icon"><i class="fa fa-user"></i></label>
                </label>
            </div>
            <div class="col-xs-4">
                <label for="name2" class="field prepend-icon">
                    <input type="text" name="customer_register_company" id="customer_register_company" class="event-name gui-input br-light light" placeholder="شرکت">
                    <label for="name2" class="field-icon"><i class="fa fa-building"></i></label>
                </label>
            </div>
        </div>
        <div class="section row mb15">
            <div class="col-xs-4">
                <label class="field select">
                    <select id="customer_Category_Register" name="customer_Category_Register"></select>
                    <i class="arrow double"></i>
                </label>
            </div>
            <div class="col-xs-4">
                <label class="field select">
                    <select id="customer_City_Register" name="customer_City_Register"></select>
                    <i class="arrow double"></i>
                </label>
            </div>
            <div class="col-xs-4">
                <label for="name1" class="field prepend-icon">
                    <input type="text" name="customer_register_postalcode" id="customer_register_postalcode" class="event-name gui-input br-light light" placeholder="کد پستی">
                    <label for="name1" class="field-icon"><i class="fa fa-envelope-o"></i></label>
                </label>
            </div>
        </div>
        <div class="section row mb15">
            <div class="col-xs-4">
                <label for="name1" class="field prepend-icon">
                    <input type="text" name="customer_register_phone" id="customer_register_phone" class="event-name gui-input br-light light" placeholder="تلفن">
                    <label for="name1" class="field-icon"><i class="fa fa-phone"></i></label>
                </label>
            </div>
            <div class="col-xs-4">
                <label for="name2" class="field prepend-icon">
                    <input type="text" name="customer_register_mobile" id="customer_register_mobile" class="event-name gui-input br-light light" placeholder="موبایل">
                    <label for="name2" class="field-icon"><i class="fa fa-mobile-phone"></i></label>
                </label>
            </div>
            <div class="col-xs-4">
                <label for="email" class="field prepend-icon">
                    <input type="text" name="customer_register_email" id="customer_register_email" class="event-name gui-input br-light bg-light" placeholder="آدرس ایمیل">
                    <label for="email" class="field-icon"><i class="fa fa-envelope-o"></i></label>
                </label>
            </div>
        </div>
        <div class="section row mb15">
            <div class="col-xs-9">
                <label for="name1" class="field prepend-icon">
                    <input type="text" name="customer_register_about" id="customer_register_about" class="event-name gui-input br-light light" placeholder="درباره">
                    <label for="name1" class="field-icon"><i class="fa fa-exclamation"></i></label>
                </label>
            </div>
            <div class="col-xs-3">
                <label for="name2" class="field prepend-icon">
                    <input type="text" name="customer_register_businescode" id="customer_register_businescode" class="event-name gui-input br-light light" placeholder="کد اقتصادی">
                    <label for="name2" class="field-icon"><i class="fa fa-terminal"></i></label>
                </label>
            </div>
        </div>
        <div class="section row mb15">
            <div class="col-xs-10">                                                    
                <label class="field prepend-icon">
                    <textarea class="gui-textarea br-light bg-light" id="customer_register_address" name="cust-note" placeholder="آدرس"></textarea>
                    <label for="cust-note" class="field-icon"><i class="fa fa-edit"></i></label>
                </label>
            </div>
            <div class="col-sm-2">
                <p class="text-left">
                    <button class="btn btn-primary btn-lg" onclick="Set_Person();" id="customer_register_Button" type="button">Register</button>
                </p>
            </div>
        </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:0)

您可以从类名中删除postfix _My。

答案 1 :(得分:0)

将此添加到您的模型__construct函数parent::__construct();或在您的函数中加载数据库库。