Load Form with Json Data from LocalStorage Key-ID to Auto-Populate Fields

After successfully setting the ID in localStorage, I now need to retrieve and display only that specific record from my JSON data.

The content of my localStorage is:

This information is obtained from my JSON data after a button click. The challenge is using the stored ID to fetch the corresponding JSON record. Below is the current AJAX call I am using, but I'm unsure how to modify it to only return the record with the specified ID. Any assistance on this matter would be greatly appreciated.

AJAX Call:

var recID = localStorage.getItem('recordID');

var Json_return = [];
jQuery(function(){
      jQuery.getJSON('mydata.php',{},function(data){
    Json_return = data;
    console.log (data);

Answer №1

To retrieve the id from local storage, use the provided code snippet:

var recID = localStorage.getItem('recordID');

var Json_return = [];
jQuery.getJSON('mydata.php',{},function(data){
 Json_return = data;
}

Next, filter the ajax call to retrieve data only for that specific id:

var filteredData = $.grep(Json_return, function(element, index) {
         return element.ID == recID  
       });
console.log(filteredData);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Serialize long values in exponential notation format using Spring MVC's REST JsonSerializer

My Spring MVC REST application has a custom Json serializer (for ObjectMapper) for handling LocalDate objects: public class DateSerializer extends JsonSerializer<LocalDate> { public LocalDateSerializer() { super(); } @Overr ...

Searching with multiple key value pairs in jQuery autocomplete is not organizing the results

In one of my projects, I am using jQuery UI autocomplete search to look for subjects. However, I have encountered a problem. You can find a replica of the search implementation in this js fiddle. The first search uses a single JSON array object without an ...

Versatile route able to handle any request thrown its way

My Node.js app is up and running smoothly using the Express.js framework. All routes in my application are set to post routes, such as: app.post('/login', function(req, res){ //perform login validation }); app.post('/AppHomepage', fun ...

Utilizing browser local storage in web development

Currently, I am in the midst of working on an e-commerce platform, a project that holds significant importance for me as it marks my debut into major projects. For the first time, I am delving into the realm of local storage to manage basket data such as q ...

Transforming a JSONP request to automatically parse a text response into JSON

If I have the following request $.ajax({ type: "GET", dataType: "jsonp", jsonp: "callback", jsonpCallback: "my_callback", url: my_https_url, headers:{"Content-Type":"text/html; charset=utf-8"}, success: function(data) { ...

Troubleshooting jQuery Ajax issues in a modularized environment

Having trouble getting this function to work properly. It's being called from a separate .js file. function TabLoaderAJAX(xurl, xdata) { var result = null; $.ajax({ type: 'POST', url: '/services/TabLoader.asmx/& ...

The SVG format quickly displays new and larger datasets on line charts without any transition effects

My goal is to create a line chart with animated transitions similar to this demo, but without the dots. I am attempting to integrate this functionality into a react component where the update method can be triggered by another component, allowing the d3 op ...

Implementing access restrictions for modules in NodeJS

In Node, is it possible to limit access or permit access only to specific modules from a particular module? Should I consider replacing the require function and object in the global scope for this purpose? I have concerns about the security of a certain mo ...

Express.js returning unexpected results when calling MySQL stored procedures

I've encountered a strange issue with a stored procedure called getUsers in MYSQL. When I execute the procedure in phpmyadmin, it returns a table of users with their data perfectly fine. However, when I try to call the same procedure from my Node.js a ...

When using json.dumps, it appends the attribute '"__pydantic_initialised__": true' to the object

I have been experimenting with fastapi and working with data from json files. One issue I encountered is that when I use app.put to add an object, json.dumps automatically adds the attribute "__pydantic_initialised__": true to the newly created o ...

Can you provide me the steps to delete the title attribute from images in Wordpress?

My client has expressed dissatisfaction with the tooltip that appears when hovering over images in certain browsers, particularly Safari. This tooltip displays the title attribute within the img tag, which is a requirement enforced by Wordpress. Even if w ...

What causes the updated value to be appended to an array when using the spread operator to modify an existing property's value?

In my state, I have an array of objects: const initialState=[{a:1},{b:2},{c:{d:3}}] const [state,setState]=useState(initialState) My goal is to modify the value of b to 5 within my event handler: function changeBToFive() { setState((state) => [ ...

No visible alterations were observed to the object following the invocation of JSONDecoder

I'm facing an issue with parsing JSON data into a struct using JSONDecoder in my function called by viewDidLoad. Even though the API call works correctly in postman, I can't seem to print the movie data in the console when I try to access it. Ins ...

An assortment of the most similar values from a pair of arrays

I am seeking an algorithm optimization for solving a specific problem that may be challenging to explain. My focus is not on speed or performance, but rather on simplicity and readability of the code. I wonder if someone has a more elegant solution than mi ...

What could be the reason for my CSS selector with :target not functioning properly?

I tried to implement the instructions I found online for using :target, but it's not working as expected. My goal is to change the background color and font color of #div1 when the first link is clicked, and to change the border of #div2 when the seco ...

Enhance web design with dynamic size pseudo elements using only CSS, no

Before the title, I've added a pseudo element with a slanted background. When the title is wrapped, it increases in height. I've been attempting to make the pseudo element adjust to the title's height, but haven't succeeded yet. I&apos ...

React Component State in JavaScript is a crucial aspect of building

What happens when the expression [...Array(totalStars)] is used within a React Component? Is the result an array with a length of 5, and what are the specific elements in this array? We appreciate your response. class StarRating extends Component { ...

Utilize ScriptControl for JSON parsing in VBA: convert output into dictionaries and collections

Looking to utilize Microsoft ScriptControl in VBA for parsing a JSON string and converting the resulting Object into Dictionary and Collection objects. While I have the parsing aspect down with ScriptControl, I'm struggling with how to translate the r ...

obtaining values from a JSON object and JSON array in java

I am struggling to generate a JSON string that combines both a JSON object and a JSON array. Here is the desired format: { "scode" : "62573000", "sname" : "Burn of right", "icd10" = [ {"icode" : "T25.229?", "iname" : "Right foot"}, {"icode" ...

The Dropdownlist jQuery is having trouble retrieving the database value

Within my database, there is a column labeled Sequence that contains integer values. For the edit function in my application, I need to display this selected number within a jQuery dropdown list. When making an AJAX call, I provide the ProductId parameter ...