通过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.

查看全部
weixin_33729196
weixin_33729196
2014/02/19 10:20
  • php
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

3个回复