title: jQuery ajax returning 'Object Object'
body: <p>I am trying to send data to a PHP script using jQuery Ajax. For some reason the Ajax request is throwing up an error and returning the following data from the PHP script - <code>[object Object]</code></p>
  
  <p>I've copied my code in below. I've also copied code using the exact same method elsewhere on the page which seems to work fine!</p>
  
  <p>Can anyone explain why this is happening?</p>
  
  <p>Firstly, the code that is working fine</p>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code> $("#reqtable a").click(function(){
    var cells = []; 
    var name;
    var account;
    var module;
    var email;
    $(this).parent().parent().find("td").each(function(){
    cells.push($(this).html());
    });
    $(this).parent().parent().find("input").each(function(){
    email = $(this).val();
    });
    $(this).parent().parent().prop('id', 'die');
    name = cells[0];
    account = cells[1];
    module = cells [2];
  
    $.ajax({
              url: "release.php",
              type: "POST",
              data: {name: name, account: account, module: module, email: email},
              success: function(){
              $("#die").remove();
             }
           });
   });
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php
  include('../../dbconnect.php');
  
  $name = $_POST['name'];
  $account = $_POST['account'];
  $email = $_POST['email'];
  $module = $_POST['module'];
  
  $releasequery = "INSERT INTO release_assignment(name, account, email, module) VALUES ('$name', '$account', '$email', '$module')";
  $release = $conn-&gt;query($releasequery);
  
  $erasequery = "DELETE FROM request_assignment WHERE email='$email' AND module = $module";
  $erase = $conn-&gt;query($erasequery);
  
  ?&gt;
  </code></pre>
  
  <p>And now the code that IS NOT working.</p>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code> $("#downloadtable a").click(function(){
    var dlcells = []; 
    var dlname;
    var dlaccount;
    var dlmodule;
    var dlemail;
    var dlsub;
    var dlpath;
  
    $(this).parent().parent().find("td").each(function(){
    dlcells.push($(this).html());
    });
    $(this).parent().parent().find("input.dlemail").each(function(){
    dlemail = $(this).val();
    });
    $(this).parent().parent().find("input.dlsub").each(function(){
    dlsub = $(this).val();
    });
    $(this).parent().parent().find("input.dlpath").each(function(){
    dlpath = $(this).val();
    });
  
    $(this).parent().parent().prop('id', 'die2');
    dlname = dlcells[0];
    dlaccount = dlcells[1];
    dlmodule = dlcells [2];
  
    $.ajax({
              url: "download.php",
              type: "POST",
              data: {dlname: dlname, dlaccount: dlaccount, dlmodule: dlmodule, dlemail: dlemail, dlsub: dlsub, dlpath: dlpath},
              success: function(data){
              $("#die2").remove();
              },
              error: function(data){
               $('#downloaddiv').html('&lt;p&gt;' + data + '&lt;/p&gt;');
              }
           });
   }); 
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php
  include('../../dbconnect.php');
  
  $name = $_POST['dlname'];
  $email = $_POST['dlemail'];
  $account = $_POST['dlaccount'];
  $module = $_POST['dlmodule'];
  $path = $_POST['dlpath'];
  $submission = $_POST['dlsub'];
  
  $feedbackquery = "INSERT INTO feedback_assignments(name, email, level, unit, assignmentpath, submission) VALUES ('$name', $email, '$account', '$module', '$path', '$submission')";
  $feedback = $conn-&gt;query($feedbackquery);
  
  $erasequery = "DELETE FROM uploaded_assignments WHERE email='$email' AND unit = $module";
  $erase = $conn-&gt;query($erasequery);
  
  ?&gt;
  </code></pre>
  
  <p>When I comment out all the PHP code and simply put <code>echo ($_POST['dlname']);</code> it returns the data <code>[object Object]</code></p>
  
  <p>Can anyone explain what is going on and why it seems to work with one block of code but not the other?</p>
  
  <p>Thanks!</p>
  
  <p>Chris</p>
  
  <p><strong>Update:</strong> It might be worth mentioning that the initial link <code>('#downloadtable a')</code> actually instigates a file download as well as the ajax call, whereas in the code that is working it simply makes the ajax call and nothing else. I don't know if this is throwing a spanner in the works but thought it worth mentioning.</p>
  
  <p><strong>Update 2:</strong> Using the jQuery Ajax error callback as described below I'm getting the following response: </p>
  
  <pre><code>{"readyState":0,"responseText":"","status":0,"statusText":"error"} 
  AJAX error: error : 
  </code></pre>
  
  <p>The code I've used in the error callback is as follows:</p>
  
  <pre><code>error: function(jqXHR, textStatus, errorThrown) {
     console.log(JSON.stringify(jqXHR));
     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
     }
  </code></pre>
  
  <p>Unfortunately I don't understand what this means. Can anyone shed any light on this?</p>
  
  <p><strong>Update 3</strong> OK, I've found the reason for Ajax blowing up on me, and it relates to update number 1 (above). Basically because the link is to a file download (a .docx file) it seems to be causing the problem with ajax. When I change the link to <code>href='#'</code> instead of <code>href="document.docx"</code>, the ajax and PHP script works.</p>
  
  <p>This throws up a new question, of course - how can I get the link to download the file whilst simultaneously updating the database?</p>