0

I want send an array to my codeigniter app for deleted. I know i can do a form with multi input same name . But can i ask how can do that without a form ? Can i post with ajax ?

//HTML Code

<li class="bigbox empty" id="bigbox_52"><a title="" href="#" class="abigbox selectbox" rel="52" style="opacity: 0.5;"></li>
<li class="bigbox empty" id="bigbox_37"><a title="" href="#" class="abigbox selectbox" rel="37" style="opacity: 0.5;"></li>
<li class="bigbox empty" id="bigbox_36"><a title="" href="#" class="abigbox selectbox" rel="36" style="opacity: 0.5;"></li>
<li class="bigbox empty" id="bigbox_38"><a title="" href="#" class="abigbox selectbox" rel="38" style="opacity: 0.5;"></li>
<li class="bigbox empty" id="bigbox_39"><a title="" href="#" class="abigbox selectbox" rel="39" style="opacity: 0.5;"></li>

<a class="delall" href="">Delete All</a>

//Jquery Code

$(".delall").click(function(){
    var values = $(".selectbox").map(function(){
    return $(this).attr('rel');
    }).get();

        return false;
});

Please help me to handle this array , soory because i m new with Jquery. Many thanks.

1
  • You could POST JSON using $.post() or $.ajax(). Commented Feb 9, 2012 at 9:40

3 Answers 3

2

You can use jQuery post (or any other AJAX call) to send an array:

$.post("test.php", { 'choices[]': ["Jon", "Susan"] });

For details, have a look here.

Sign up to request clarification or add additional context in comments.

Comments

1

How about something like this:

function postArray(){
  var mapTo = function(){
    return $(this).attr('rel');
  },

  values = $(".selectbox").map(mapTo).get(),
  url = "http://my-server.com/resource.php";

  $.ajax({
    type: 'POST',
    url: url,
    data: {'values[]':values},
    success: function(response){
      console.log(response);
    }
  });
}

$(".delall").click(postArray);

jQuery's documentation is thorough and has some good examples. Docs on $.ajax can be found here: http://api.jquery.com/jQuery.ajax/

Comments

0

It's not quite clear what you're trying to accomplish with the list elements, but yes, first construct an object in Javascript and call the $.post() function. Why not use checkboxes? What's all this bigbox stuff?

$(document).ready(function(){

    //your previous code here to get the proper values.

    var url = "yourapp.com/yourcontroller/yourfunction";
    $.post(url, values, function(response){
      //when the server responds, log the response.  
      console.log(response);
    })
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.