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

  • Home
  • SEARCH
  • 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 7011315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:06:41+00:00 2026-05-27T22:06:41+00:00

Am receiving null from json post using jquery. see my code below in order.

  • 0

Am receiving null from json post using jquery. see my code below in order.

user fills in this form and submits:

<form name="newsletterSignup" id="newsletterSignup" method="post">

        <input type="text" name="firstName" id="firstName" type="text" autocomplete="off" placeholder="Enter your name" />

        <input type="text" name="email" id="email" type="text" autocomplete="off" placeholder="Enter a valid email address"/>

        <input type="submit" name="newsletterSubscribe" id="newsletterSubscribe" value="Sign me up now!" /> 

    </form>

Then this is run:

var BASE_URL = 'http://www.thegurucoder.com/';

$('#newsletterSignup').submit(function()
{

    var ajaxURL = BASE_URL + '_php/ajax/newsletterSubscribe.php';

    $.ajax({
        type: 'POST',
        url: ajaxURL,
        data: { firstName:$('#newsletterSignup #firstName').val(), email:$('#newsletterSignup #email').val()},
        dataType: 'json',
        success: function(data){

            alert(data);

            if(data.redirect == 'true')
            {

                window.location = data.url;

            }
            else
            {

                $(this).notify({prependTo:'#master', type:'negative', message:data.message, delay:3200, animation:'slide'});

            }

        }
    });

    return false;

});

Which in turn runs this:

function newsletterSubscribe()

{

if(isset($_POST['newsletterSubscribe']))
{

    header('Content-Type: application/json');

    $db = new Connection(DB_HOST, DB_USER, DB_PASS, DB_NAME);

    $firstName = $_POST['firstName'];
    $email = $_POST['email'];

    if($email != '')
    {

        if(isDuplicateValue('subscribers', 'email', $email))
        {

            echo json_encode(array(
                'message' => 'You have already subscribed to this newsletter.',
                'redirect' => 'false'
            ));

        }
        else
        {

            $parameters = array(
                'table' => 'subscribers',
                    'fieldsAndValues' => array(
                    'firstName' => $firstName,
                    'email' => $email,
                    'addedDate' => datetime()
                    )
            );

            $db->insert($parameters);

            echo json_encode(array(
                'redirect' => 'true',
                'url' => BASE_URL.'subscribed'
            ));

        }

    }
    else
    {

        echo json_encode(array(
            'message' => 'You did not enter a valid email address.',
            'redirect' => 'false'
        ));

    }

}

}

And the problem is:

Uncaught TypeError: Cannot read property ‘redirect’ of null

These are the headers i am getting in inspector.

Request URL:http://www.thegurucoder.com/_php/ajax/newsletterSubscribe.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:17
Content-Type:application/x-www-form-urlencoded
Cookie:PHPSESSID=f3015d3c6fa08e53fc562477da0f563f
Host:www.thegurucoder.com
Origin:http://www.thegurucoder.com
Referer:http://www.thegurucoder.com/blog
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
X-Requested-With:XMLHttpRequest
Form Dataview URL encoded
firstName:
email:
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:close
Content-Encoding:gzip
Content-Language:en-UK
Content-Length:20
Content-Type:text/html; charset=UTF-8
Date:Thu, 05 Jan 2012 15:21:54 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
Vary:Accept-Encoding
X-Powered-By:PHP/5.2.14
  • 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-27T22:06:41+00:00Added an answer on May 27, 2026 at 10:06 pm

    The problem with your code is that you are not posting ‘newsletterSubscribe’ field to your php file in ajax request but on that php file you are checking for ‘newsletterSubscribe’ in if condition as if(isset($_POST[‘newsletterSubscribe’])) .

    So in php code change if(isset($_POST['newsletterSubscribe'])) to if(isset($_POST['firstName'])) and it will work for sure.

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

Sidebar

Related Questions

I'm using spring MVC for receiving a JSON from client and automatically create an
I am receiving a JSON response from our server and it is compressed using
After receiving very good correction from fuzzy lollipop, I amended my code to create
I'm trying to create a dynamic ItemizedOverylay (please see the code below) on Google
I'm receiving a json array from python as the return of curl_exec in PHP
I'm receiving data from web-services in XML and I'm using that data via objects,
I am using BroadcastReceiver class for receiving the sms. My main class code is:
Hello I am receiving a JSON file from an URL in an Android device.
Receiving this error (JSON.parse: unexpected character) when I try to parse a JSON validated
I'm receiving feedback from a developer that The only way visual basic (6) can

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.