[object Object] parsererrorSyntaxError:意外的令牌<在位置0的JSON中

时间:2017-06-29 19:13:29

标签: javascript php jquery ajax codeigniter

我使用ajax在mysql数据库中插入数据提交此错误将会显示。我正在制作这个 在codeigniter框架中。我是ajax的新bie.I我无法弄清楚哪里出错了。这是我的代码



  $('#btnSave').text('saving...'); //change button text
            $('#btnSave').attr('disabled', true); //set button disable
            var url;

//           if (save_method == 'add') {
            url = "http://[::1]/sms/sms/forms/1";
//           } else {
//               url = "";
////           }

            var  radio=$('#radio').val();
            var  st_id=$('#st_id').val();
            var  branch_type=$('#branch_type').val();
            bname=$('#bname').val();
            bcode=$('#bcode').val();
            baddress=$('#baddress').val();
            var  bcity=$('#bcity').val();
            var  zcode=$('#zcode').val();
            var  bstates=$('#bstates').val();
            var  bcountry=$('#bcountry').val();
            var  bpno=$('#bpno').val();
            var  bemail=$('#bemail').val();
            var  bweb=$('#bweb').val();
            var  Latitude=$('#Latitude').val();
            var  Longtitude=$('#Longtitude').val();
            var  noted=$('#noted').val();
            var  addedby=$('#addedby').val();

            // ajax adding data to database


            $.ajax({
                type: 'ajax',
                data: {st_id: st_id, branch_type: branch_type, bname: bname, bcode: bcode, baddress: baddress,
                    bcity: bcity, zcode: zcode, bstates: bstates, bcountry: bcountry, bpno: bpno, bemail: bemail,
                    bweb: bweb, Latitude: Latitude, Longtitude: Longtitude, noted: noted, addedby: addedby},
                url: url,
                method: 'post',
                asysc: false,
                dataType: 'json',
                success: function (data) {

                    if (data.status) //if success close modal and reload ajax table
                    {

                    }
                    else {

        }
                    $('#btnSave').text('Add Record'); //change button text
                    $('#btnSave').attr('disabled', false); //set button enable


                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR + textStatus + errorThrown);
                    $('#btnSave').text('Add Record'); //change button text
                    $('#btnSave').attr('disabled', false); //set button enable
//
                }

            });

my php code 

  $submit['sys_t_id']=$this->input->post('st_id');
                $submit['t_id']=$this->input->post('branch_type');
                $submit['name']=$this->input->post('bname');
                $submit['code']=$this->input->post('bcode');
                $submit['address']=$this->input->post('baddress');
                $submit['city']=$this->input->post('bcity');
                $submit['zip']=$this->input->post('zcode');
                $submit['state']=$this->input->post('bstates');
                $submit['country']=$this->input->post('bcountry');
                $submit['contact_no']=$this->input->post('bpno');
                $submit['email']=$this->input->post('bemail');
                $submit['web']=$this->input->post('bweb');
                $submit['latitude']=$this->input->post('Latitude');
                $submit['longitude']=$this->input->post('Longtitude');
                $submit['note']=$this->input->post('noted');
                $submit['addedby']=$this->input->post('addedby');
                $submit['addedon']=date('Y-m-d:H-m-s');
                $insert = $this->Smsmodal->insert('branch_info',$submit);
                echo json_encode(array("status" => TRUE));
              




1 个答案:

答案 0 :(得分:0)

我认为你有服务器错误!在成功函数中使用console.log(data)来查看服务器输出。