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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:39:48+00:00 2026-06-17T01:39:48+00:00

I have an array or a javascript object that I create like this: arr[arr.length]=obj

  • 0

I have an array or a javascript object that I create like this:
arr[arr.length]=obj
where the obj is a classic JSON string like {"id":1}.

So arr seems to be an array of JavaScript Objects.

I can access to it like this:
arr[1], arr[2].
It could be even like alert(arr[1].id);

If i do:
alert(JSON.stringify(arr));
I get the following:

[{"id":"2305","col":"1"},{"id":"2308","col":"1"},{"id":"2307","col":"1"},{"id":"2306","col":"1"}]

Whereas
alert(arr);
Gives me something like:

[object Object],[object Object],[object Object],[object Object],[object Object]

Now I need to pass it to a PHP script using jQuery’s AJAX method. But it seems that it can get only combined strings like:

{"id":"2305","col":"1"} or {"id":"2305","col":"1","id":"2305","col":"1"}

But JSON.stringify parses the arr object successfully and my previous example of string I have seems to be a valid JSON string. How can I pass to PHP, should I really change the whole format of structure to be like the last sample?

UPD:
i forgot to mention that PHP’s POST array is null if send ‘{},{},{}’ string to it rather then ‘{}’ string.

UPD:
I rewrote the code that was generated the string. Now i have a string like this:

{"2305":"1","2306":"1"}

It works if i pass it to PHP directly, like this:

   $.post({url: '../getItems2Cart.php', data:{"2305":"1","2306":"1"} ,
       success: function(response){alert(response);}
   });

If i send it like this, php return empty POST array:

$.post({url: '../getItems2Cart.php', data: JSON.stringify(str),.
       success: function(response){alert(response);}
});

To get clear, alert returns a proper JSON strong now:

alert('json str to php '+JSON.stringify(str));
//json str to php {"2305":"1","2306":"1"}

Ahh.. yes, and str is an javascript object, not string.

  • 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-17T01:39:49+00:00Added an answer on June 17, 2026 at 1:39 am

    Can send the JSON and use json_decode() to turn it into a php array.

    $.post('server/path', { jsonData: JSON.stringify(arr)}, function(response){
       /* do something with response if needed*/
    });
    

    in php:

    $arr=json_decode( $_POST['jsonData'] );
    /* return first ID as test*/
    echo $arr[0]['id'];
    /* or dump whole array as response to ajax:*/
    print_r($arr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this array, that I want to parse into javascript. $offerText[] = (
I know that I can create an associative array like this: var MyAssocArray =
I'd like to create a Javascript object that can save and load its state
I have a custom Javascript object that I create with new , and assign
I have a collection of objects in JavaScript like this: Object collection = new
I have a simple JavaScript Array object containing a few numbers. [267, 306, 108]
I have an array in javascript that I need to join and send through
I have an array on javascript and i insert the elements on it like
1) I have this Javascript array: lang=new Array(); lang[sq]=Albanian; lang[ar]=Arabic; lang[en]=English; lang[ro]=Romanian; lang[ru]=Russian; 2)
I'd like to have JavaScript objects within another JavaScript object as such: Issues: -

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.