title: AJAX POST handler causing "uncaught exception"
body: <p>So I've been banging my head against my desk for a few hours on this one and i'm not getting anywhere so help would really be appreciated.</p>
  
  <p>The code below has two jquery event handlers which fire off an ajax request. The first one uses GET and the data it gets back from the server is JSON encoded - it works fine. The second one ( "button#addTx" ) returns causes Firebug to produce this error:</p>
  
  <blockquote>
    <p>uncaught exception: [Exception...
    "prompt aborted by user"  nsresult:
    "0x80040111 (NS_ERROR_NOT_AVAILABLE)" 
    location: "JS frame ::
    resource://gre/components/nsPrompter.js
    :: openTabPrompt :: line 468"  data:
    no]</p>
    
    <p>Line 0</p>
  </blockquote>
  
  <p>which is no help to at all. The server side script is printing raw html to the screen and the aim is that a jquery html replace will be used to update to the page which initiates the request. The data is POSTed correctly as the database updates but beyond that I have no clue. I have rewritten it to try a GET and still produce the same error :-(</p>
  
  <p>Help would be amazing - thank you, Simon</p>
  
  <pre><code>$(document).ready(function(){
  $("button.delete").click(function(){
      var txid = this.id;
      var amountID = "#amount" + txid;
      var amount = $(amountID).html();
      // &lt;![CDATA[
  
      var url = "delete.php?txid=" + txid + "&amp;am=" + amount;
      $.ajax({
          type: "GET",
          url: url,
          success: function(msg){
              txid = "ul#" + txid;
              $(txid).hide();
  
              var values = msg;
              var e = "#" + values.category + "AmountLeft";
              var a = values.amount;
  
              $(e).html(a);
          }
      });
  });
  $("button#addTx").click(function(){
  
      // &lt;![CDATA[
  
  
      var url = "addTran.php";
      //var dataV = var data = "category=" + document.getElementById("category").value + "&amp;what=" + document.getElementById("what").value + "&amp;amount=" + document.getElementById("amount").value + "&amp;date=" + document.getElementById("date").value;
      $.ajax({
          type: "POST",
          url: "addTran.php",
          //async: false,
          data: "category=Groceries&amp;what=Food&amp;amount=2.33&amp;date=2/3/2011",
          success: function(msg){
              $("transList").replaceWith(msg);
          }
      });
  });
  });
  </code></pre>
  
  <p>and here is the server side script</p>
  
  <pre><code>&lt;?php
  session_start();
  include('functions.php');
  //if the user has not logged in
  if(!isLoggedIn())
  {
      header('Location: index.php');
      die();
  }
  
  
  $category = $_POST['category'];
  $what = $_POST['what'];
  $amount = $_POST['amount'];
  $date = $_POST['date'];
  
  $category = mysql_real_escape_string($category);
  $what = mysql_real_escape_string($what);
  $amount = mysql_real_escape_string($amount);
  $date = mysql_real_escape_string($date);
  
  $date = convertDate($date);
  
  //add trans to db
  include('dbcon.php');
  $query = "INSERT INTO transactions ( category, what, amount, date) VALUES ( '$category','$what','$amount','$date');";
  mysql_query($query);
  
  //grab the remaining amount from that budget
  $query = "SELECT amount_left FROM cards WHERE category = '$category';";
  $result = mysql_query($query);
  $row = mysql_fetch_array($result, MYSQL_ASSOC);
  $oldAmountLeft =  $row["amount_left"];
  
  //update the amount left
  $amountLeft = $oldAmountLeft - $amount;
  
  mysql_free_result($result);
  
  //add new value to db
  $query = "UPDATE cards SET amount_left = '$amountLeft' WHERE category = '$category';";
  mysql_query($query);
  
  
  
  //generate the list of remaining transactions, print to screen to send back to main page
  
  $query = "SELECT txid, what, amount, date FROM transactions WHERE category = ('$category');";
  $result = mysql_query($query);
  
  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      $d = convertDateReverse($row["date"]);
      $what = $row["what"];
      $amount = $row["amount"];
      $txid = $row["txid"];
      ?&gt;
          &lt;li&gt;&lt;ul class="trans" id="&lt;? echo $txid; ?&gt;"&gt;&lt;li class="date"&gt;&lt;? echo $d; ?&gt;&lt;/li&gt;&lt;li class="what"&gt;&lt;? echo $what; ?&gt;&lt;/li&gt;&lt;li class="amount" id="amount&lt;? echo $txid; ?&gt;"&gt;&lt;? echo $amount; ?&gt;&lt;/li&gt;&lt;button class="delete" id="&lt;? echo $txid; ?&gt;"&gt;Delete&lt;/button&gt;&lt;li&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
      &lt;?
  }
  mysql_free_result($result);
  
  
  
  mysql_close();
  
  header("Content-type: application/x-www-form-urlencoded"); //do I need this? I have a " header("Content-type: application/json"); " in the working one
  
  ?&gt;
  </code></pre>