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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:57:50+00:00 2026-05-26T01:57:50+00:00

I am using the $.post() method to retrieve a json formatted string which looks

  • 0

I am using the $.post() method to retrieve a json formatted string which looks like this:

{elementid:10},{elementid:11},{elementid:12},{elementid:14},{elementid:15}

In the success callback function of $.post(), I would like to loop the values of this json formatted string but I can’t figure out how to do it.

  // data returns {elementid:10},{elementid:11},{elementid:12},{elementid:14}, etc.

  $.post('form.php',

        {'postvalues' : input_ids},

        function(data){

              var elements = Array();

              elements = [data];

              for(var i=0; i<elements.length; i++) {
                    var value = elements[i]['elementid'];
                    alert('value = '+value);
              }
  });

When I do this, instead of getting value = 10, value = 11, value = 12, etc. in the alert box,
I get value = undefined

What must I change in the format of the variable ‘data’ so that it will be interpreted as array values and not a string?

thanks for your help

  • 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-26T01:57:51+00:00Added an answer on May 26, 2026 at 1:57 am

    Your string isn’t valid JSON if you don’t have the '[' and ']' characters.

    You can add those in , then parse it using the jQuery.parseJSON()[docs] method.

    elements = jQuery.parseJSON( '[' + data + ']' );
    

    …but it would be better if you sent correct JSON data from the server.

    Also, your JSON keys must be wrapped in double quotes.

    {"elementid":10},{"elementid":11},{"elementid":12},{"elementid":14},{"elementid":15}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the difference when using GET or POST method? Which one is more secure?
How to send an http request with either post/get method using javascript as an
$.ajax({ url: /cgi-bin/stats.exe, method: post, async: false, data: { refresh: a41 } }); Using
I'm using the AcceptVerbs method detailed in Scott Gu's Preview 5 blog post for
I'm using this simple code to retrieve a value from a PHP script: package
I am using the Tweetstream gem to retrieve statuses from Twitter. This works: Tweetstream::Client.new('user',
I am using jquery ajax method to retrieve data. It is working in IE
I'm using jQuery's $.ajax method to send and retrieve data to a REST service.
In a POST to an MVC controller, I'm using JQuery to send a JSON
I found this great tutorial on how to use JSON to retrieve Twitter updates,

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.