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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:54:08+00:00 2026-06-17T08:54:08+00:00

I am posting some data to a PHP page with AJAX, but I can’t

  • 0

I am posting some data to a PHP page with AJAX, but I can’t decode it. json_decode() returned NULL. So I figured that if I’d echo it I could run it through jsonlint. But nothing showed up. To find out if the data reaches the PHP page I tried to var_dump() the data. Strange enough it showed:

string(75) "{\"title\":\"fds\",\"body\":\"fds\",\"tags\":\"fds\",\"type\":\"question\"}"

So the data reaches the page. I ran it through jsonlint after removing the backslashes and it said the JSON was valid. How is this possible?

I got a valid JSON string of 75 characters according to var_dump() and jsonlint, but I can’t echo it or json_decode() it.

EDIT:
Apparently I did something wrong, I can echo it now (I probably made a typo in the $_POST array key). It echoes this:

{\"title\":\"tre\",\"body\":\"tre\",\"tags\":\"tre\",\"type\":\"question\"}

Once again, without backslashes JSONLint tells me it is valid JSON.

EDIT 2:
Here’s the PHP code:

// code to check if the user is logged in
$post = json_decode($_POST['q']);
echo "var_dump(\$_POST['q']): ";
var_dump($_POST['q']);
echo "<BR /><BR />";
echo "var_dump(\$post): ";
var_dump($post);    

Ouput:

var_dump($_POST['q']): string(74) "{\"title\":\"gfd\",\"body\":\"gf\",\"tags\":\"gfd\",\"type\":\"question\"}" 

var_dump($post): NULL

JS code:

var simpleObj = {title: "rew", body: "rew", tags: "rew", type: "question"};
$.post('savepost.php', "q=" + JSON.stringify(simpleObj), function(data) {
    $('#resultDiv').html("DATA: " + data);
});

Final edit:
I finally solved it myself. I actually discovered the problem even before I asked, but thought it was ‘harmless’ and didn’t think that could cause this problem.

  • 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-17T08:54:08+00:00Added an answer on June 17, 2026 at 8:54 am

    I found out the answer! When I ran it through jsonlint.com it said it was invalid because of the backslashes. I thought these were just there to mark the quotes in the JSON as normal quotes, not string ending and starting quotes and I thought they were ‘harmless’.
    I then thought of the function addslashes(), and figured there should be a reversed one too. I found stripslashes() and that solved the problem.

    New code:

    // code to check if the user is logged in
    $post = json_decode(stripslashes($_POST['q']));
    echo "var_dump(\$_POST['q']): ";
    var_dump($_POST['q']);
    echo "<BR /><BR />";
    echo "var_dump(\$post): ";
    var_dump($post);    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi guys i'm posting some data to controller using jquery ajax, but i am
I am posting some data using ajax. I want to manipulate that data and
I'm posting data to a page called process.aspx that handles some business logic with
Im currently posting some data to a php webservice using a class that extends
I am posting some form values through ajax to a PHP script. The PHP
Im trying to post some data to a php page and the posted elements
I'm trying to upload files and posting some variables via URLConnection and multipart/form-data. But
I am posting some data from android to PHP server using Httppost. Everything was
I'm posting some data to a php file with jquery. The PHP file just
I'm trying to POSTing some data (a JSON string) from a php script to

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.