title: How to post an array using AJAX to PHP?
body: <p>I want to post an array to PHP using AJAX and on success returns the value back to JavaScript. Here's my code.</p>
  
  <p>JavaScript:</p>
  
  <pre><code>$(document).ready(function(){
  $.ajax({
      type: "POST",
      url: "phparray.php",
      data: {
          array1: phparray
      },
  
      success: function(data){
          alert("success");
          alert(data);
      }
  });
  });
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script type="text/javascript" src="jquery-2.0.2.js"&gt;&lt;/script&gt;
      &lt;script&gt;
       var phparray = jQuery.makeArray();
       for(var i=0; i&lt;10 ; i++){
          phparray.push(i); 
       }
  
      &lt;/script&gt;
      &lt;script type="text/javascript" src="phparraypost.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
  $n=$_POST['array1'];
  
  echo $n;
  
  
  ?&gt;
  </code></pre>
  
  <p>The data I get back says </p>
  
  <pre><code>&lt;br /&gt; &lt;b&gt;Notice&lt;/b&gt;: Array to string conversion in &lt;b&gt;C:\xampp\htdocs\php\phparray.php&lt;/b&gt; on line &lt;b&gt;4&lt;/b&gt;&lt;br /&gt; Array
  </code></pre>
  
  <p>and I don't have an idea what might be wrong with it.</p>
  
  <p>The HTML, PHP and JavaScript code are in different files.</p>