title: NaN error in ajax callback
body: <p>I am getting a <code>NaN</code> error in my ajax callback function and can only think it has to do with an array in PHP. I have been trying to find ways to correct it but have come up against a brick wall.</p>
  
  <p>What is supposed to happen is that PHP queries the database and if there are no results send a response to ajax and issue the error message. However, all I am getting is <code>NaN</code>. The error stems from the <code>success</code> code below.</p>
  
  <p>I would be grateful if someone could point out my error.</p>
  
  <p>PHP code:</p>
  
  <pre><code>$duplicates = array();
  
  foreach ($boxnumber as $val) {
      if ($val != "") {
          mysql_select_db($database_logistor, $logistor);
          $sql = "SELECT custref FROM boxes WHERE custref='$val' and status = 'In'";
          $qry = mysql_query($sql) or die(mysql_error());
  
          if (mysql_num_rows($qry) &lt; 1) {
              $duplicates[] = '[ ' . $val . ' ]';
              $flag = 1;
          } else {
              $duplicates[] = $val;
          }
      }
  }
  
  //response array with status code and message
  $response_array = array();
  if (!empty($duplicates)) {
      if ($flag == 1) {
  //set the response
          $response_array['status'] = 'error';
          $response_array['message'] = 'ERROR: ' . implode(',', $duplicates) . ' needs to be in the database to be retrived.';
      }
  //if no errors
  } else {
  
  //set the response
      $response_array['status'] = 'success';
      $response_array['message'] = 'All items retrieved successfully';
      $response_array['info'] = ' You retrieved a total of: ' . $boxcount . ' boxes';
  }
  
  //send the response back
  echo json_encode($response_array);
  </code></pre>
  
  <p>Relevant ajax:</p>
  
  <pre><code>$("#brtv-result").html(msg.message+msg.info);
  </code></pre>
  
  <p>jQuery code:</p>
  
  <pre><code>$(function() {
  
   $("#BRV_brtrv").submit(function() {
  
     var send = $(this).serialize();
  
      $.ajax({
        type: "POST",
        url: "boxrtrv.php",
        cache: false,
        data: send,
        dataType: "json",
        success: function(msg) {
         if( msg.status === 'error') {
            $("#brtv-result").fadeIn(1000).delay(1000).fadeOut(1000);
            $("#brtv-result").removeClass('error');
            $("#brtv-result").removeClass('success');
            $("#brtv-result").addClass(msg.status);
            $("#brtv-result").html(msg.message);
         }
  
         else {
            $("#brtv-result").fadeIn(2000).delay(2000).fadeOut(2000);
            $("#brtv-result").removeClass('error');
            $("#brtv-result").addClass('success');
            $("#brtv-result").addClass(msg.status);
            $("#brtv-result").html(msg.message+msg.info);
            //location.reload(true);
            //$('#brtv-result').addClass("result_msg").html("You have successfully retrieved: "+data.boxnumber).show(1000).delay(4000).fadeOut(4000);
            $("#BRV-brtrv-slider").val(0).slider("refresh");
            $("input[type='radio']").attr("checked",false).checkboxradio("refresh");
            var myselect = $("select#BRV-brtrv-department");
            myselect[0].selectedIndex = 0;
            myselect.selectmenu("refresh");
            var myselect = $("select#BRV-brtrv-address");
            myselect[0].selectedIndex = 0;
            myselect.selectmenu("refresh");
        }
  
       },
        error:function(){
           $("#brtv-result").show();
           $("#brtv-result").removeClass('success');
           $("#brtv-result").addClass('error');
           $("#brtv-result").html("There was an error submitting the form. Please try again.");
       }
     });
     return false;
    });
  });
  </code></pre>