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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:02:31+00:00 2026-06-13T10:02:31+00:00

I have a javascript object which I want to pass to a PHP file

  • 0

I have a javascript object which I want to pass to a PHP file while using jQuery’s ajax-implementation.

I’ve tried to directly pass it to it but this doesn’t work, because it isn’t escaped or anything. I’ve tried to use JSON.stringify but this isn’t working for me either.

Is there a way to ‘serialize’ a javascript object to a POST-string?

Update, I’m using JSON.stringify() again. The result is:

The result of JSON.stringify() is:

{\"label\":\"Borne, Overijssel, Nederland\",\"value\":\"Borne, Overijssel, Nederland\",\"geocode\":{\"address_components\":[{\"long_name\":\"Borne\",\"short_name\":\"Borne\",\"types\":[\"locality\",\"political\"]},{\"long_name\":\"Borne\",\"short_name\":\"Borne\",\"types\":[\"administrative_area_level_2\",\"political\"]},{\"long_name\":\"Overijssel\",\"short_name\":\"OV\",\"types\":[\"administrative_area_level_1\",\"political\"]},{\"long_name\":\"Nederland\",\"short_name\":\"NL\",\"types\":[\"country\",\"political\"]}],\"formatted_address\":\"Borne, Nederland\",\"geometry\":{\"bounds\":{\"ca\":{\"b\":52.2832527,\"f\":52.3151634},\"ea\":{\"b\":6.688658900000064,\"f\":6.801415300000031}},\"location\":{\"Ya\":52.3002366,\"Za\":6.753725799999984},\"location_type\":\"APPROXIMATE\",\"viewport\":{\"ca\":{\"b\":52.2832527,\"f\":52.3151634},\"ea\":{\"b\":6.688658900000064,\"f\":6.801415300000031}}},\"types\":[\"locality\",\"political\"]}}

When I do a json_decode it results to NULL. Any suggestions?

  • 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-13T10:02:32+00:00Added an answer on June 13, 2026 at 10:02 am

    If your passing an object as a string thats in legitmate JSON format, to PHP try using

    json_decode() on the php side of things. Example

    <?php
       $ojb = json_decode($_POST['my_json_string']);
    ?>
    

    What this will do is turn your object into an array or object depending on which version of PHP you are using, and in some cases the object will turn into an array with multiple objects in it.. example:

    Array(
        [0] stdClass (
                'key1'=>'val1'
                'key2'=>'val2'
                'key3'=>'val3'
             )
    )
    

    which I know the above isnt a good representation, but its a representation in the lines there of.

    After that PHP side you can work with the variable $ojb like any other array/object.

    $something = $ojb[0]->key1;
    

    EDIT
    I notice your string now. The fact that the quotes are escaped in the string, breaks the fact that its a JSON object, with that you can do one of two things.. Either just pass the object to PHP through your post/get as is, without running it through strigify or.. you could try on the PHP side, if there is a need to strigfy it..

    $ojb = stripslashes($_POST['my_json_string']); $ojb = json_decode($ojb);

    which will attempt to remove the slashes from the quotes, before putting it through the decode process.

    http://php.net/manual/en/function.json-decode.php

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

Sidebar

Related Questions

I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
Let's suppose I want to create a javascript class/object/function which have a method that
I have a javascript object, which I've added a number of prototyped functions to,
Can I´m asking for advice. I have function which should return javascript object function
I have a JavaScript object with thousands of properties and what i want if
I have a javascript object with a bit of jquery for visual effect. I
I have a javascript object, and I want to recursively search it to find
Suppose I have a Javascript object which is initialized var letters = {q:0, t:0,
I have a JavaScript class where pass options object in init function. this options
I have several GWT Maps API JavaScriptObjects (LatLng, Polyline) which I want to send

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.