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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:11:51+00:00 2026-05-27T02:11:51+00:00

I have an AJAX script that post data in one of my PHP file:

  • 0

I have an AJAX script that post data in one of my PHP file:

     var _lname = $('#ptLastName').val();
    var _fname = $('#ptFirstName').val();
    var _mname = $('#ptMiddleName').val();
$.ajax({
                type: "POST",
                url: ".././CheckPerson.php",
                data: "{'lastName':'" + _lname + "','firstName':'" + _fname + "','middleName':'" + _mname + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var res = response.d;
                    if (res == true) {
                        jAlert('Person Name already exists!', 'Error');
                        return;
                    }

It works fine and I can see the JSON Data posted in the Firebug console. The problem is with this PHP code:

$firstname = json_decode($_POST['firstName']);
$lastname = json_decode($_POST['lastName']);
$middlename = json_decode($_POST['middleName']);
$response = array();

The above PHP code seems that it can’t recognize the 'firstName','lastName', and 'middleName' as a posted JSON parameter, and return an Undefined index: firstName in C:... something like that for all the posted parameters.

I also tried using $data = $_POST['data'] and $_REQUEST['data'] to get all the JSON parameters and decode it using json_decode($data); but didn’t work.

I’ve also used the AJAX shortened code for post $.post('.././CheckPerson.php', {data: dataString}, function(res){ });, it works great with my PHP file and my PHP file can now read lastName, firstName, and middleName, but i think it is not a JSON data but only a text data because firebug can’t read it as JSON data. Now,i’m confused how will my PHP file read the JSON data parameters.Do you guys have any suggestions about this?

  • 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-27T02:11:52+00:00Added an answer on May 27, 2026 at 2:11 am

    The problem is that dataType: "json" doesn’t mean that you’re posting json, but that you’re expecting to receive json data from the server as a result of your request. You could change your post data to:

    data: {myPostData : "{'lastName':'" + _lname + "','firstName':'" + _fname + "','middleName':'" + _mname + "'}"}
    

    and then parse it on your server like

    $myPostData = json_decode($_POST['myPostData']);
    $firstname = $myPostData["firstName"];
    $lastname = $myPostData["lastName"];
    $middlename = $myPostData["middleName"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery-ajax function that sends data to a php script and the
In my document I have this script: $.ajax({ type:POST,url:ajax.php,data:data, success: function() { //onsuccess },
I have a jQuery script: $.ajax({ url: /scripts/secure/development/ajax.asp, type: POST, dataType: text, data: cmd=addresses,
i have a script that calls a php file and gets an JSON object
Within my index.php file I have an AJAX function that will call a function
I have a JQUERY AJAX post function that will work if there is one
I have a ajax call to a php script that updates my MySQL DB
I have an ajax call to one php script via jquery but it takes
At the minute I have a page with an AJAX script that searches a
I have a script that retrieves objects from a remote server through an Ajax

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.