普通网友 2014-02-19 10:20
浏览 21

通过AJAX传递多个值

I am stuck in passing the multiple value through AJAX call in Codeigniter.

My View is :

<script>
$( document ).ready(function() {

    var current_id = 0;
 $('#btn').click(function(){
     nextElement($('#Outer_00'));
 })

 function nextElement(element){
     var newElement = element.clone()
     .find("input:text").val("").end();

     var id = current_id+1;
     current_id = id;
     if(id <10)id = "0"+id;

     $('input', newElement).attr("id", id );
     newElement.appendTo($("#elements"));
            if($('#elements').find('div').length=='5')
    {
    $('#btn').prop('disabled',true);
    }
 }


$('#exercises').on('click', '.remove', function() {
if($('#elements').find('div').length<'6')
{

$('#btn').prop('disabled',false);
}
  if($('#elements').find('div').length=='1')
{
    $('.remove').addAttr("disabled",true);
}

$(this).parent().remove();

return false; //prevent form submission
});
});
</script>

/******************************

<script>
var  base_url = '<?=base_url()?>';
$(document).ready(function()
    {
        $('#Edit').click(function()
        {
            $('#Name').removeAttr("disabled");


    });

    $('#Add').click(function()
    {
        $('#Name').attr("disabled","disabled");
        $('#Phone').attr("disabled","disabled");
        $('#email').attr("disabled","disabled");
        $('#CurrentlyLocated').attr("disabled","disabled");
        $('#KeySkills').attr("disabled","disabled");
        //var queryString = $('#form1').serialize();



                $.ajax({
                    url: '<?php echo site_url('PutArtistProfile_c/formDataSubmit');?>',
                  type : 'POST', //the way you want to send datas to your URL
                  data: {Name:$("#Name").val(), Phone: $("#Phone").val(), email: $("#email").val(),
                         birthday: $("#birthday").val(), bornIn: $("#bornIn").val(),
                         CurrentlyLocated: $("#CurrentlyLocated").val(), KeySkills: $("#KeySkills").val(),
                         Audio1: $("#00").val(), Audio2: $("#01").val(), Audio3: $("#02").val(),Audio4: $("#03").val(), Audio5: $("#04").val(),
                         },                     
                  success : function(data)
                  { //probably this request will return anything, it'll be put in var "data"
                    $('body').html(data);                   

                  }
               });  

    });
    });
</script>

<p>

<div id="elements">
<div id="Outer_00">
Audio:  <input type="text" id="00" value="">
<input type="button" class="remove" value="x"></button>

</div>
</div>

<div id="count"></div>
<input type="button" id="btn" value="Add Audio"></button>
</p>

enter image description here

My Controller is :

public function formDataSubmit()
{

    $queryAudio1 = $this->input->post('Audio1');
            $queryAudio2 = $this->input->post('Audio2');
            $queryAudio3 = $this->input->post('Audio3');
            $queryAudio4 = $this->input->post('Audio4');
            $queryAudio5 = $this->input->post('Audio5');

}

How can I pass Multiple Values of text box? The above code is passing the values to the controller. But on clicking 'x' Button the value of text box is been getting deleted, but the id of the textbox is getting Incremented, Thus I am not able to pass the further values of textbox to controller via AJAX. Please help me over here.

  • 写回答

3条回答 默认 最新

  • weixin_33713707 2014-02-19 10:22
    关注

    instead of doing :

     data: {Name:$("#Name").val(), Phone: $("#Phone").val(), email: $("#email").val(),
                                 birthday: $("#birthday").val(), bornIn: $("#bornIn").val(),
                                 CurrentlyLocated: $("#CurrentlyLocated").val(), KeySkills: $("#KeySkills").val(),
                                 Audio1: $("#00").val(), Audio2: $("#01").val(), Audio3: $("#02").val(),Audio4: $("#03").val(), Audio5: $("#04").val(),
                                 }, 
    

    You can do as

    data:$("#Form_id").serialize(); // all form data will be passed to controller as Post data.
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛