Ajax Post Not Sending Array

Ajax Post Not Sending Array

Hello,

Back again with another question lol

So I have been trying to send an array of a UL:LI to a PHP page. The array is made and through jQuery can be read just fine. The problem is when I use the $.ajax() function the array is not sent.

jQuery.html
  1. <html>

  2. <head>
  3. <title>jQuery Testing</title>
  4. <script type="text/javascript" src="templates/js/jquery.js"></script>
  5. <script>
  6. $(document).ready(function() {
  7. $('.list1 li').dblclick(function() {
  8. $(this).clone().appendTo('.list2');
  9. });
  10. $('#test').click(function() {
  11. var test_list = [];
  12. $("ul.list2 li").each(function() { test_list.push($(this).attr('id')) });
  13. $.each(test_list, function(index, value) { 
  14.  alert(index + ': ' + value); 
  15. });
  16. $.ajax({
  17. url: "post.php",
  18. type: "POST",
  19. dataType: "html",
  20. data: test_list,
  21. //data: { 0: 'test' },
  22. success:  function(data) {
  23. alert(data);
  24.  }
  25. });
  26. });
  27. });
  28. </script>
  29. </head>

  30. <body>

  31. <ul class="list1">

  32. <li id="1">List 1</li>
  33. <li id="2">List 2</li>
  34. <li id="3">List 3</li>
  35. <li id="4">List 4</li>
  36. </ul>
  37. <br />
  38. <br />
  39. <br />
  40. <ul class="list2">

  41. <li id="1">List 1</li>
  42. <li id="2">List 2</li>
  43. <li id="3">List 3</li>
  44. <li id="4">List 4</li>
  45. </ul>
  46. <br />
  47. <br />
  48. <input type="button" id="test" value="Test" />
Everything about cloning and appending works (10-12).

Lines (14-34) Is what is giving me the problem.

As I said, the array is made from the list. list2 to be exact. That works fine, and using the .each() function does what I want it to do (this will be deleted after it works). 

Line 27 seems to be the problem. When I comment it out and uncomment Line 28 everything works fine and the php file returns the right value.

Just for you to see here is the post.php file.

  1. <?php

  2. if($_POST[0]) {
  3. echo 'yes<br />'.$_POST[0];
  4. } else {
  5. echo 'no';
  6. }

  7. ?>
Any help as to why?