发送第二个表单jquery ajax codeigniter

时间:2016-06-13 03:08:35

标签: jquery ajax codeigniter

我想将字段从一个表单传递给控制器​​,并根据其输出,以第二种形式构造值并提交它。但是,我不知道如何提交第二份表格。

我试过这样。

我的观点

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

 <script type="text/javascript">
 $(document).ready(function() {
 $("#enviar").click(function() {
 $("#type_c option:selected").each(function() {
 type_c = $('#type_c').val();
 project = $('#project').val();
 $.post("<?= base_url('test/other_form')?>", {
 type_c : type_c,
 project : project 
 }, function(data) {
 $("#location").html(data);
 });
 });
 })
 });
 </script>

 <script type="text/javascript">
$(document).ready(function() {
 $("#enviar2").click(function() {
 $("#type_d option:selected").each(function() {
 type_d = $('#type_d').val();
 project_2 = $('#project_2').val();
 $.post("<?= base_url('test/other_form2')?>", {
 type_d : type_d,
 project_2 : project_2 
 }, function(data) {
 $("#location").html(data);
 });
 });
 })
 });
 </script>

</head>
<body>

<div id="initialize">
 <select name="type_c" id="type_c">
 <option value="1">uno</option>
 <option value="2" selected>dos</option>
 <option value="3">tres</option>
 </select>

 <input type="text" name="project" id="project">

<input type="submit" value="enviar" id="enviar" >
</div>


    <div name="location" id="location">

我的控制器

public function other_form(){
        $value = $this->input->post('type_c');
        $value2 = $this->input->post('project');

        echo '<select name="type_d" id="type_d">
 <option value="'.$value.'" selected>'.$value.'</option>
 </select>';

        echo '<input type="submit" id="enviar2" name="enviar2" value="elijo este">';

        echo "<script>
                document.getElementById('initialize').style.display = 'none';
            </script>";
    }

    public function other_form2(){
    echo 'sss<hr>';
        echo '<pre>';
        var_dump($_REQUEST);
        echo '</pre>';

        //echo "<script>document.getElementById('options_close_temp').style.display = 'none';</script>";
    }

但第二种形式_永远不会发送请求

0 个答案:

没有答案