Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否只向控制器提交下拉列表的数据,并使用ajax将其更新到数据库中?_Php_Ajax_Sqlite_Codeigniter - Fatal编程技术网

Php 是否只向控制器提交下拉列表的数据,并使用ajax将其更新到数据库中?

Php 是否只向控制器提交下拉列表的数据,并使用ajax将其更新到数据库中?,php,ajax,sqlite,codeigniter,Php,Ajax,Sqlite,Codeigniter,[这是我的视图表,它从我的数据库sqlite3中获取数据。但我想更新同一页上的测试列,这就是为什么我使用ajax调用,但我不知道如何在ajax函数中传递数据并将其获取到控制器中。我真的是个新手 <table class="table table-bordered table-striped" id="tab"> <thead>

[这是我的视图表,它从我的数据库sqlite3中获取数据。但我想更新同一页上的测试列,这就是为什么我使用ajax调用,但我不知道如何在ajax函数中传递数据并将其获取到控制器中。我真的是个新手

    <table class="table table-bordered table-striped" id="tab">
                            <thead>
                                <tr>
                                
                                    <th>Sr</th>
                                    <th>Type</th>
                                    <th>Software</th>
                                    <th>Owner</th>
                                    <th>Description</th>
                                    <th>Input</th>
                                    <th>Output</th>
                                    <th>Remarks</th>
                                    <th>Priority</th>
                                    <th width='60'>Test</th>
                                    <th width='60'>Implement</th>
                                    <th width='40'>Edit</th>
                                    <th width='40'>Delete</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php $counter =0; if(!empty($requirements)) { foreach($requirements as $requirement ) {  $counter++?>
                                <tr>
                                    <td> <?php echo $counter;?></td>
                                    <td><?php echo $requirement['type'];?></td>
                                    <td><?php echo $requirement['software'];?></td>
                                    <td><?php echo $requirement['owner'];?></td>
                                    <td><?php echo $requirement['description'];?></td>
                                    <td><?php echo $requirement['input'];?></td>
                                    <td><?php echo $requirement['output'];?></td>
                                    <td><?php echo $requirement['remarks'];?></td>
                                    <td><?php echo $requirement['pri'];?></td>
                                    <td>
                                    
                                    <?php
                                    $id=$requirement['req_id'];
                                    $selected=$requirement['tested'];
                                    $options=array('Tested','Not Tested');
                                    echo"<select class='' name='tested' id='tested' onChange='update(event,$id)'>";
                                    foreach($options as $option){
                                    if($selected==$option){
                                    echo"<option selected='selected' value='$option'>$option</option>";
                                    }
                                    else{
                                    echo"<option value='$option'>$option</option>";
                                    }
                                    }
                                    echo"</select>";
                                     ?>
                                    </td>
                                    <td><?php echo $requirement['implemented'];?></td>
                                    <td>
                                        <a class="btn btn-secondary" href="<?php echo base_url().'index.php/rest_req/edit/'.$requirement['req_id'];?>" >Edit</a>
                                    </td>
                                    <td>
                                        <a class="btn btn-danger" href="<?php echo base_url().'index.php/rest_req/deleteReq/'.$requirement['req_id'];?>"onclick="return confirm('Do you really want to delete this requirement?')" >Delete</a>
                                    </td>
                                </tr>
                                <?php } } else { ?>
                                <tr>
                                    <td colspan="13">No Requirements Found...</td>
                                </tr>
                                <?php } ?>
                                </tbody>
                            </table>
这是我的模型,我从中获取数据,不确定这是否正确

     public function updateS($req_id,$formArray){
            $this->db->where('req_id',$req_id);
            $this->db->update('req_data',$formArray);
        }

大家好,欢迎来到这个平台

通过ajax发出POST请求有多种方法。其中一种方法如下:

$.post(
"http://someurl",
{ 
字段1:值1,
字段2:值2
},
功能(响应数据){
控制台日志(responseData);
}
);
这几乎是您尝试的方式,除了尝试在数据参数中插入数据的那一刻。使用这种方式时不需要这样做

您的案例的正确代码为:

函数更新(事件,id){
//日志(event.target.value);
测试的var=事件.target.value;
//控制台日志(已测试);
var id=id;
//console.log(id);
美元邮政(
“身份证”,
{
测试:测试,
}
);
}
另一种方式更高级,看起来像:

$.ajax({
url:“http://someurl",
类型:“POST”,
数据:{
字段1:值1,
字段2:值2
},
成功:函数(responseData){console.log(responseData);},
数据类型:“文本”
});
因此,对于您的情况,它可能看起来像:

函数更新(事件,id){
//日志(event.target.value);
测试的var=事件.target.value;
//控制台日志(已测试);
var id=id;
//console.log(id);
$.ajax({
url:“id”,
类型:“POST”,
数据:{
测试:测试
},
成功:函数(responseData){console.log(responseData);},
数据类型:“文本”
});
}
使用其中一种方法后,您应该通过以下方式在控制器中获得测试的
值:

$tested=$\u POST['tested];

大家好,欢迎来到这个平台

通过ajax发出POST请求有多种方法。其中一种方法如下:

$.post(
"http://someurl",
{ 
字段1:值1,
字段2:值2
},
功能(响应数据){
控制台日志(responseData);
}
);
这几乎是您尝试的方式,除了尝试在数据参数中插入数据的那一刻。使用这种方式时不需要这样做

您的案例的正确代码为:

函数更新(事件,id){
//日志(event.target.value);
测试的var=事件.target.value;
//控制台日志(已测试);
var id=id;
//console.log(id);
美元邮政(
“身份证”,
{
测试:测试,
}
);
}
另一种方式更高级,看起来像:

$.ajax({
url:“http://someurl",
类型:“POST”,
数据:{
字段1:值1,
字段2:值2
},
成功:函数(responseData){console.log(responseData);},
数据类型:“文本”
});
因此,对于您的情况,它可能看起来像:

函数更新(事件,id){
//日志(event.target.value);
测试的var=事件.target.value;
//控制台日志(已测试);
var id=id;
//console.log(id);
$.ajax({
url:“id”,
类型:“POST”,
数据:{
测试:测试
},
成功:函数(responseData){console.log(responseData);},
数据类型:“文本”
});
}
使用其中一种方法后,您应该通过以下方式在控制器中获得测试的
值:

$tested=$\u POST['tested];

函数更新(event,id){var tested=event.target.value;//console.log(tested);var id=id;//console.log(id);$.ajax({url:“id”,type:“POST”,数据:{tested:tested},成功:函数(responseData){console.log(responseData);},数据类型:“text”};}使用此命令后,我在控制台中没有得到任何值,我也不知道如何更新数据库中的值。您能帮我更新数据库中的值吗?如果您没有看到任何控制台日志,这意味着由于某种原因请求未成功。了解-原因很重要。
success:function(responseData){console.log之后(responseData);},
add
fail:function(error){console.warn(error);},
并查看一下您在控制台中看到的内容。在添加此项之后,我也只是在控制台中得到一个空行。:(其他人可以帮助吗?函数更新(event,id){var tested=event.target.value;//console.log(tested);var id=id;//console.log(id);$.ajax({url:“id”,类型:“POST”,数据:{tested:tested},成功:函数(responseData){console.log(responseData);},数据类型:“text”};}使用此命令后,我在控制台中没有得到任何值,我也不知道如何更新数据库中的值。您能帮我更新数据库中的值吗?如果您没有看到任何控制台日志,这意味着由于某种原因请求未成功。了解-原因很重要。
success:function(responseData){console.log之后(responseData);},
add
fail:function(error){console.warn(error);},
并查看您在控制台中看到的内容。添加此项后,我在控制台中也只得到一个空行。:(其他人可以帮助吗?
     public function editS($req_id)
        {
            $this->load->model('rest_model');
            $requirement = $this->rest_model->getReq($req_id);
            $data = array();
            $data['requirement'] = $requirement;
            $test= Request.Form("tested");
            $formArray = array();
            $formArray['tested'] = $this->input->post('tested');
            $this->rest_model->updateS($req_id, $formArray);
            $this->session->set_flashdata('success', 'Requirement Updated successfully.');
        }
     public function updateS($req_id,$formArray){
            $this->db->where('req_id',$req_id);
            $this->db->update('req_data',$formArray);
        }