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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:57:08+00:00 2026-06-09T10:57:08+00:00

I am sending data via jQuery’s .ajax method to my PHP file. Both files

  • 0

I am sending data via jQuery’s .ajax method to my PHP file. Both files are on the same domain. The file making the post looks like this..

$('#pdf').click(function() {                    
    var proj_name = $('#proj_name').text();
    var date = $('#date').text();
    var req_comp_date = $('#req_comp_date').text();
    var status = $('#status').text();
    var secondUserID = $('#secondUserID').text();

    var postData = {
        "proj_name" : proj_name,
        "date" : date,
        "req_comp_date" : req_comp_date,
        "status" : status,
        "secondUserID" : secondUserID,
    };

    console.log(postData);

    $.ajax({
        type: "POST",
        url: "test.php",
        data: postData, 
        success: function(){
            alert(proj_name + ' ' + status);
            window.open("test.php"); 
        }
    });
});

And the PHP file getting the post data is…

//request parameters
$proj_name = $_POST['proj_name'];
$date = $_POST['date'];
$req_comp_date = $_POST['req_comp_date'];
$status = $_POST['status'];
$secondUserId = $_POST['secondUserId'];

echo 'postData: ' . var_dump($_POST);

if ($_POST)){
    echo $proj_name;
    echo $date;
    echo $req_comp_date;
    echo $status;
    echo $secondUserId;
} else {
    echo 'problem';
}

In my firebug console, I can see that the parameters posted with .ajax, but I cannot get the post via PHP. Can anyone help me out please? 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-09T10:57:09+00:00Added an answer on June 9, 2026 at 10:57 am

    Add the error callback to your to your $.ajax call to debug if the request is failing.

    $.ajax({
        type: "POST",
        url: "test.php",
        data: postData, 
        success: function(){
            alert(proj_name + ' ' + status);
            window.open("test.php"); 
        },
        // Alert status code and error if fail
        error: function (xhr, ajaxOptions, thrownError){
            alert(xhr.status);
            alert(thrownError);
        }
    });
    

    Update

    Change this:

    if ($_POST)){
        echo $proj_name;
        echo $date;
        echo $req_comp_date;
        echo $status;
        echo $secondUserId;
    } else {
        echo 'problem';
    }
    

    To this:

    if ($_POST)){
        // Make a array with the values
        $vals = array(
            'proj_name'     => $proj_name,
            'date'          => $date,
            'req_comp_date' => $req_comp_date,
            'status'        => $status,      
            'secondUserId'  => $secondUserid
        );
    
        // Now we want to JSON encode these values to send them to $.ajax success.
        echo json_encode($vals);
    
        exit; // to make sure you arn't getting nothing else
    
    } else {
        // so you can access the error message in jQuery
        echo json_encode(array('errror' => TRUE, 'message' => 'a problem occured'));
        exit;
    }
    

    Now in your jQuery .success callback:

    success: function(data){ // Our returned data from PHP is stored in "data" as a JSON Object
        alert(data.req_comp_date); // access your returned vars like this.
        // data.date; // is your posted date.. etc
        alert(data.proj_name + ' ' + data.status);
        window.open("test.php"); 
    
        // You can also get your error message like so..
        if(data.error) // if its true, we have a error, so display it.
             alert('ERROR: ' + data.message); 
    
    },
    

    You dont really have to do this next bit (jquery does a good job of determining the data type returned), but its nice to have it in the code to understand what is being returned.

    $.ajax({ ...
        type: "POST",
        url: "test.php",
        data: postData, 
        dataType: "json" // <-- Add this to tell jquery, we are being returned a JSON object.
    .... });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When sending data via POST or GET with jQuery you use for format {
Im using jQuery getJSON method to get data from my database via some php
I'm sending a JSON object to PHP using jQuery via $.ajax({ url: myURL, type:
I've got a problem sending a file to a serverside PHP-script using jQuery's ajax
I am sending post data via ajax, and that data looks like this: var
I'm sending user data via jQuery to TCPDF, but it does not display any
I am trying to POST a raw string via jQuery.ajax() e.g., contact_list=352345 I have
I am sending an Array of values through Ajax via jQuery with a Play
I have a problem posting file via ajax jQuery function. I have something like
I'm reading an xml file with PHP and pulling it into jQuery via a

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.