如何通过jquery将数组发送到php,而不使用具有多个输入相同名称的表单

如何通过jquery将数组发送到php,而不使用具有多个输入相同名称的表单,php,jquery,post,Php,Jquery,Post,我想向我的codeigniter应用程序发送一个数组,以便删除。我知道我可以做一个多输入相同名称的表单。但是我能问一下,没有表格怎么办?我可以用ajax发布吗 //HTML代码 <li class="bigbox empty" id="bigbox_52"><a title="" href="#" class="abigbox selectbox" rel="52" style="opacity: 0.5;"></li> <li class="bigbo

我想向我的codeigniter应用程序发送一个数组,以便删除。我知道我可以做一个多输入相同名称的表单。但是我能问一下,没有表格怎么办?我可以用ajax发布吗

//HTML代码

<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>

请帮助我处理这个数组,soory,因为我是Jquery新手。非常感谢。

您可以使用jQuery
post
(或任何其他AJAX调用)发送数组:

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

有关详细信息,请查看。

您可以使用jQuery
post
(或任何其他AJAX调用)发送数组:

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

有关详细信息,请看一看。

不太清楚您试图用列表元素实现什么,但是可以,首先在Javascript中构造一个对象并调用$.post()函数。为什么不使用复选框呢?这些大盒子是什么东西

$(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);
    })
});

现在还不太清楚如何使用列表元素,但是可以,首先在Javascript中构造一个对象并调用$.post()函数。为什么不使用复选框呢?这些大盒子是什么东西

$(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);
    })
});

像这样的怎么样:

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的文档非常全面,并且有一些很好的例子。关于
$.ajax
的文档可以在这里找到:

像这样的东西怎么样:

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的文档非常全面,并且有一些很好的例子。
$.ajax
上的文档可以在这里找到:

您可以使用$.POST()或$.ajax()发布JSON。您可以使用$.POST()或$.ajax()发布JSON。