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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:28:47+00:00 2026-05-15T14:28:47+00:00

I’m having a problem trying to return a specific record using jQuery and JSON.

  • 0

I’m having a problem trying to return a specific record using jQuery and JSON. I’m passing a variable to the function and want to output only the data matching the id I’ve set when the function is executed.

Right now, my function looks like this:

function getEffectsData(myNum){
    $.getJSON("jsonscript.php", { id: +myNum },function(data){
       var x = data.x;
       //DO SOME STUFF
    });
}

The JSON output looks like this:

{"stuff": [ { "id":1, "x":3, "y":6, "z":-6 },{ "id":2, "x":2, "y":7, "z":-3 }]}

The only thing I know is that the correct variable is being passed to the function. After that, nothing happens. Very new at this, so any help is greatly appreciated.

EDIT:
I appreciate everybody’s input on this. To clarify, I am trying to return the data from only the object that’s id matches myNum. I want to be able to access all of the data from that object, but only that object. I have no idea where that object will be in the array. I simplified the ids and the data in my question to help clarify the problem.

Thanks again.

  • 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-15T14:28:48+00:00Added an answer on May 15, 2026 at 2:28 pm

    You can access x from your JSON like this:

    var x1 = data.stuff[0].x; // the first object's x key
    var x2 = data.stuff[1].x; // the second object's x key
    

    Because your JSON tree looks like this:

    { // base object
        "stuff": [ // array
        { // 0.: object
            "id": 1,  // key => value
            "x" : 3,  // key => value
            "y" : 6,  // key => value
            "z" : -6  // key => value
        },
        { // 1.: object
            "id": 2,  // key => value
            "x" : 2,  // key => value
            "y" : 7,  // key => value
            "z" : -3  // key => value
        }]
    }
    

    So with data.stuff[0].x you select stuff object then it’s first element and then its x key.

    But If you want to handle all the x key for example, then you need to loop through the stuff array by a simple for loop or the $.each method.


    UPDATE

    As for your question. If you want to get the object with id myNum you have 2 possibilities:

    1. if you possess jsonscript.php you can send the data only with the correct id from the server, because you pass the id to it by { id: +myNum } which is the second parameter of getJSON

    2. You loop through the data until you find the object with the correct id

      var object; 
      $.each(data.stuff, function(i, obj) {
        if (obj.id === myNum) object = obj;
      });
      // now object is the one with the right id
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 438k
  • Answers 438k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A structure in C and a structure in C# are… May 15, 2026 at 4:40 pm
  • Editorial Team
    Editorial Team added an answer The \r\n is simply a windows linefeed (i.e. an "enter"… May 15, 2026 at 4:40 pm
  • Editorial Team
    Editorial Team added an answer IP address might change in the case of mobile clients,… May 15, 2026 at 4:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.