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 8581909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:09:50+00:00 2026-06-11T21:09:50+00:00

When I make an AJAX call from a form, it shows it is successful,

  • 0

When I make an AJAX call from a form, it shows it is successful, but the data object is null. The code is as follows:

$.ajax(
  {
    url: 'shipprocess.php',
    dataType: 'json',
    type: 'POST',
    success: function(data)
      {
    alert('Data is: ' + data);
    alert('The AJAX request was a success.');
      },
    'error': function()
      {
    alert('An unexpected error occurred.');
      }
  });
return false;

The form looks like this:

<div class="processedDate">
<form action="shipprocess.php" method="POST" id="shipProcess2" name="shipProcess2">
<input type="hidden" name="empID" value="1" />
<input type="hidden" name="thisOrderID" id="thisOrderID2" value="2" />
<label>Date Shipped </label>
<input type="text"  name="shipDate" id="shipDate2" class="shipDate" size="20" value="" />
<input type="submit" name="shipped" id="shipped2" class="shipped" value="Shipped!" />
</form>
</div>

After the AJAX call is made, Firebug shows the status as 200 and content length as 0. The script that processes the form is called shipprocess.php. It echos the following data when the return: false; line is commented out:

[ { "sd": "2012-09-17", "eid": "1", "oid": "2", "efn": "Johnathan", "eln": "Smith" } ]

For some reason, the script keeps alerting that data is null. A complete example can be found at http://www.yellowcas.com/ship/shipexample.php. This example shows the alert message that the data object is null when you submit the form. I also have a complete example of the data that the shipprocess.php script returns at http://www.yellowcas.com/ship/shipexample1.php. I have used AJAX before to populate the city and state input fields for a zip code that is entered by the user. The jQuery script is almost identical except for the fact that I use GET instead of POST for the zip code form.

I have tried declaring the header in PHP as JSON data, but that doesn’t help either. Firebug doesn’t seem to be giving me any helpful information either. I have tested the script using a different file called testjson.html. In that file, I put valid JSON data as the only line in the file with no headers at all, and it returns the data variable as an object. That example is at http://www.yellowcas.com/ship/shipexample2.php. I couldn’t post more than 2 hyperlinks. If you would like to see the code for shipprocess.php, I will gladly post it. I just don’t want to make this post too long. Any ideas would be greatly appreciated. Thank you.

I decided to post the shipprocess.php code to be sure you can see what I have done.It is as follows:

<?php
require_once('dblogin.php');
require_once('dbconnect.php');
require_once('funcs.php');
$err = array();
$datePattern = "!^(\\d\\d)[-/](\\d\\d)[-/](\\d\\d(?:\\d\\d)?)$!";
$psErr = "Shipping date is required.";
$emErr = "Employee ID is missing.";
$orErr = "Order ID is missing.";
if(isset($_POST['shipped']))
  {
    $postEID = clean($_POST['empID'],$emErr,$n);
    $postOID = clean($_POST['thisOrderID'],$orErr,$n);
    $postShipDate = clean($_POST['shipDate'],$psErr,$n);
    $now = date("Y-m-d H:i:s");
    if($postEID == $emErr)
      {
    $err[] = $postEID;
      }
    else
      {
    $query = "SELECT FK_UserID,FirstName,LastName FROM employees WHERE EmployeeID = '$postEID'";
    $res = mysql_query($query);
    if(mysql_num_rows($res) < 1)
      {
        $err[] = "Employee does not exist.";
      }
    else
      {
        while($row = mysql_fetch_assoc($res))
          {
        $retUserID = $row['FK_UserID'];
        $retFirstName = $row['FirstName'];
        $retLastName = $row['LastName'];
          }
      }
      }
    if($postOID == $orErr)
      {
    $err[] = $postOID;
      }
    if($postShipDate == $psErr)
      {
    $err[] = $postShipDate;
      }
    else
      {
    if (preg_match($datePattern,$postShipDate,$sMatches))
      {
        $sMonth = $sMatches[1];
        $sDay = $sMatches[2];
        $sYear = $sMatches[3];
        if(checkdate($sMonth,$sDay,$sYear))
          {
        $shipDate = "$sYear-$sMonth-$sDay";
          }
        else
          {
        $err[] = "Invalid shipping date.";
          }
      }
    else
      {
        $err[] = "Invalid Shipping Date";
      }
      }
    if(empty($err))
    //  Keep processing the information if there are no errors.
      {
    $data[] = "$postEID,$shipDate,$postOID,$now,$retFirstName,$retLastName";
      }
    else
    //  Return the errors to the user so corrections can be made.
      {
        $data[] = implode(",",$err);
      }
    for ($i=0;$i<sizeof($data);$i++)
      {
    $info = explode(",",$data[$i]);
    $data[$i] = $info;
      }
    $result = array();
    for ($y=0;$y<sizeof($data);$y++)
      {
    if (($data[$y][0]) !== false)
      {
        array_push($result, array("sd"=>$data[$y][1], "eid"=>$data[$y][0], "oid" => $data[$y][2], "efn"=>$data[$y][4], "eln"=>$data[$y][5]));
      }
    if (count($result) > 2)
      {
        break;
      }
      }
  }
echo array_to_json($result);
?>

Please try out the three example pages I have provided to see what the different results are. Thank you.

  • 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-06-11T21:09:51+00:00Added an answer on June 11, 2026 at 9:09 pm

    Your code lacks at least 2 things:

    1: When posting with Ajax, you have to send post data. So you have to tell what data you want to send. Most of the time it will be the serialized form data, but it could be anything.

    var dataString = 'name=Gr G';
    $.ajax(
      {
        url: 'shipprocess.php',
        dataType: 'json',
        data: dataString,
        type: 'POST',
        ...
    

    2: You expect a return value, but you do not send a return value. In shipprocess.php after processing you should echo somethning like this:

    ...    
    echo 'data received and processed';
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to make a jQuery AJAX call from a form, but how
Given an instantiated JavaScript object/class can I make an Ajax call from that class
I want to make an ajax call, but I want to make sure it
I call sortable.stop() to make an ajax call to store some data after drag
I want to make an ajax call from jQuery to my server. Basically, I
I'm trying to to make AJAX call with the jQuery library using the $.ajax()
I want to make an ajax call to server. I need to fetch the
I am trying to make an ajax call using $.get() where I want to
i am trying to make a ajax call by making use of jquery UI
Hi I have been trying to make a ajax call to a JSP page.

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.