Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6581279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:07:58+00:00 2026-05-25T16:07:58+00:00

I am getting a NaN error in my ajax callback function and can only

  • 0

I am getting a NaN 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.

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 NaN. The error stems from the success code below.

I would be grateful if someone could point out my error.

PHP 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) < 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);

Relevant ajax:

$("#brtv-result").html(msg.message+msg.info);

jQuery 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;
  });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:07:58+00:00Added an answer on May 25, 2026 at 4:07 pm

    NaN (pronounced nan, rhymes with man) only happens when you try to do an operation which requires a number operand. For example, when you try to Number('man') you’ll get this error.

    What you return from your PHP file, is simply an array which contains simply data. So, the problem is in your JavaScript. You have to send more parts of your JavaScript, so that we can see it thoroughly.

    However, I recommend that you use Firebug and set a breakpint at the correct place (the callback function start), and check the stack trace of the calls to diagnose the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
I am getting NaN error while clicking radio button first. The page have a3
I am getting an error Object (NaN, NaN) has no method 'extend' , when
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
Getting a 'marshal data too short' error when trying to install the mysql gem
Getting the following error, which I understand and have seen before. But one thing
Guys, Iknow this sounds ridiculous, but I'm only getting the rsult NaN of this...
I'm trying to add through a jquery event and I'm getting NaN. What am
I'm getting a message NAN within the UITextField when i'm trying to calculate the
i have problem in getting and testing the return value of ajax. my code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.